问题:
json解析int类型不符合预期,使用json.NewDecoder解决。
示例如下:
package mainimport ("bytes""encoding/json""fmt"
)func main() {data1 := map[string]interface{}{}data1["id"] = int64(444109192883284478)data1["name"] = "xiaozhu"data2 := map[string]interface{}{}data2["id"] = int64(444109192883284477)data2["name"] = "xiaozhu2"data := make([]map[string]interface{}, 2)data[0] = data1data[1] = data2dataBytes, _ := json.Marshal(data)fmt.Printf("dataBytes: %v \n", string(dataBytes))var payload1 []map[string]interface{}var payload2 []map[string]interface{}json.Unmarshal(dataBytes, &payload1)fmt.Printf("payload1: %v \n", payload1)decoder := json.NewDecoder(bytes.NewReader(dataBytes))decoder.UseNumber()if err := decoder.Decode(&payload2); err == nil {fmt.Printf("payload2: %v \n", payload2)}
}