处理格式为 []uint8
而不是 JSON 的 http resp.Body
的最佳方法是什么?
我想将字节转换为 float64
。
这是返回值响应:
value : %!F([]uint8=[48 46 48 48 49 50 53 53 50 49])
最佳答案
尝试使用 strconv
包 ( play ) 中的 ParseFloat
:
b := []uint8{48, 46, 48, 48, 49, 50, 53, 53, 50, 49}
f, err := strconv.ParseFloat(string(b), 64)
if err != nil {
// Handle parse error
}
fmt.Printf("%f\n", f) // 0.001255
关于go - 将 []uint8 转换为 float64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21592555/