Ich versuche, JSON-Antwort zu analysieren, die wie folgt aussieht:In gehen, was ist json.Unmarshall maximale Tiefe?
{
"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!"
}
}
]
}
]
}
I json.Unmarshal
und das Bestehen der folgenden Struktur als Schnittstelle bin mit:
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
}
}
}
}
Allerdings ist json.Unmarshal
nicht überein JSON Antwort auf eine der structs in Messaging
Diese Funktion gibt das Problem genau:
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)
}
Dies ist die Ausgabe:
{Object:page Entry:[{Id:185985174761277 Time:1462333588680 Messaging:[{Sender:{Id:} Recipient:{Id:} Timestamp:0 Message:{Mid: Seq: Text:}}]}]}
und wie Sie sehen können, werden alle Felder in der Nachricht Struktur nicht gesetzt sind.
Meine Frage ist, gibt es eine maximale Tiefe, die json.Unmarshal kann übereinstimmen? und wenn nicht, was mache ich falsch?
Int64, wie sie ziemlich groß sind :) – smnpl
und bitte nicht ignoriert zurückgegebene Fehler in gehen. –
das war das genaue Problem. Ich wusste nicht, dass ich Strings anstelle von Int64 in diesen Feldern hatte! Vielen Dank. – ILikeTacos