小编Lei*_*Cao的帖子

使用\ u0000\x00转到json.Unmarshal键

这是Go playground链接.

基本上'\u0000'我的JSON字符串键中有一些特殊字符():

var j = []byte(`{"Page":1,"Fruits":["5","6"],"\u0000*\u0000_errorMessages":{"x":"123"},"*_successMessages":{"ok":"hi"}}`)
Run Code Online (Sandbox Code Playgroud)

我想将它解组成一个结构:

type Response1 struct {
    Page   int
    Fruits []string
    Msg    interface{} `json:"*_errorMessages"`
    Msg1   interface{} `json:"\\u0000*\\u0000_errorMessages"`
    Msg2   interface{} `json:"\u0000*\u0000_errorMessages"`
    Msg3   interface{} `json:"\0*\0_errorMessages"`
    Msg4   interface{} `json:"\\0*\\0_errorMessages"`
    Msg5   interface{} `json:"\x00*\x00_errorMessages"`
    Msg6   interface{} `json:"\\x00*\\x00_errorMessages"`
    SMsg   interface{} `json:"*_successMessages"`
}
Run Code Online (Sandbox Code Playgroud)

我尝试了很多,但它没有用.此链接可能有助于golang.org/src/encoding/json/encode_test.go.

string json go unmarshalling

4
推荐指数
1
解决办法
1745
查看次数

如何在Golang中的运行时中动态转换类型?

这是我的示例:http : //play.golang.org/p/D608cYqtO5

基本上我想这样做:

theType := reflect.TypeOf(anInterfaceValue)
theConvertedValue := anInterfaceValue.(theType)
Run Code Online (Sandbox Code Playgroud)

reflection runtime go

0
推荐指数
1
解决办法
740
查看次数

标签 统计

go ×2

json ×1

reflection ×1

runtime ×1

string ×1

unmarshalling ×1