Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在go中,json.Unmarshall的最大深度是多少?_Json_Go - Fatal编程技术网

在go中,json.Unmarshall的最大深度是多少?

在go中,json.Unmarshall的最大深度是多少?,json,go,Json,Go,我试图解析JSON响应,如下所示: { "object": "page", "entry": [ { "id": 185985174761277, "time": 1462333588680, "messaging": [ { "sender": { "id": 105370

我试图解析JSON响应,如下所示:

{
    "object": "page",
    "entry": [
        {
            "id": 185985174761277,
            "time": 1462333588680,
            "messaging": [
                {
                    "sender": {
                        "id": 1053704801343033
                    },
                    "recipient": {
                        "id": 185985174761277
                    },
                    "timestamp": 1462333588645,
                    "message": {
                        "mid": "mid.1462333588639:d44f4374dfc510c351",
                        "seq": 1948,
                        "text": "Hello World!"
                    }
                }
            ]
        }
    ]
}
我正在使用
json.Unmarshal
并将以下结构作为接口传递:

type Message struct {
    Object string
    Entry  []struct {
        Id        int64
        Time      int64
        Messaging []struct {
            Sender struct {
                Id string
            }
            Recipient struct {
                Id string
            }
            Timestamp int64
            Message   struct {
                Mid  string
                Seq  string
                Text string
            }
        }
    }
}
但是,
json.Unmarshal
Messaging

此函数准确地再现问题:

type Message struct {
    Object string
    Entry  []struct {
        Id        int64
        Time      int64
        Messaging []struct {
            Sender struct {
                Id string
            }
            Recipient struct {
                Id string
            }
            Timestamp int64
            Message   struct {
                Mid  string
                Seq  string
                Text string
            }
        }
    }
}
func testStruct() {
    jsonResponse := []byte(`{
    "object": "page",
    "entry": [
        {
            "id": 185985174761277,
            "time": 1462333588680,
            "messaging": [
                {
                    "sender": {
                        "id": 1053704801343033
                    },
                    "recipient": {
                        "id": 185985174761277
                    },
                    "timestamp": 1462333588645,
                    "message": {
                        "mid": "mid.1462333588639:d44f4374dfc510c351",
                        "seq": 1948,
                        "text": "oijsdfoijsdfoij"
                    }
                }
            ]
        }
    ]
}`)
    var m Message
    json.Unmarshal(jsonResponse, &m)
    fmt.Println(string(jsonResponse))
    fmt.Printf("%+v\n", m)
}
这是输出:

{Object:page Entry:[{Id:185985174761277 Time:1462333588680 Messaging:[{Sender:{Id:} Recipient:{Id:} Timestamp:0 Message:{Mid: Seq: Text:}}]}]}
如您所见,消息结构中的所有字段都没有设置


我的问题是,有没有json.Unmarshal可以匹配的最大深度?如果没有,我做错了什么?

我认为json.Unmarshal上没有最大深度


在您的代码中,
Message
字段中的
Seq
字段被定义为字符串,
Sender
receiver
中的
Id
字段也是字符串,而在json中它们是整数。这应该是缺少字段的罪魁祸首。

我认为json.Unmarshal上没有最大深度


在您的代码中,
Message
字段中的
Seq
字段被定义为字符串,
Sender
receiver
中的
Id
字段也是字符串,而在json中它们是整数。这应该是缺少字段的罪魁祸首。

Int64,因为它们非常大:)这正是问题所在。我没有意识到这些字段中有字符串而不是int64!谢谢。Int64因为它们很大:)这就是问题所在。我没有意识到这些字段中有字符串而不是int64!谢谢