100%兼容标准库
替换
import "encoding/json"
json.Marshal(&data)
为
import jsoniter "github.com/json-iterator/go"
var json = jsoniter.ConfigCompatibleWithStandardLibrary
json.Marshal(&data)
替换
import "encoding/json"
json.Unmarshal(input, &data)
为
import jsoniter "github.com/json-iterator/go"
var json = jsoniter.ConfigCompatibleWithStandardLibrary
json.Unmarshal(input, &data)
func demo() {
api := jsoniter.ConfigCompatibleWithStandardLibrary
stream := api.BorrowStream(nil)
defer api.ReturnStream(stream)
stream.WriteObjectStart()
stream.WriteObjectField("hello")
stream.WriteString("world")
stream.WriteMore()
stream.WriteObjectField("nice")
stream.WriteFalse()
stream.WriteObjectEnd()
b := stream.Buffer()
fmt.Printf("%s\n", b) // 输出 {"hello":"world","nice":false}
}