(un -) marshalling json golang nicht funktioniert

Ich hab das Spiel mit Gehen und bin ratlos, warum json encode und decode funktionieren nicht für mich

Ich denke, ich kopierte die Beispiele fast wortwörtlich, aber die Ausgabe sagt beide marshal und unmarshal geben keine Daten zurück. Sie brauchen auch nicht eine Fehlermeldung zu geben.

kann jemand Tipp, wo ich bin mache ich falsch?

mein Beispiel-code: Gehen Spielplatz

package main

import "fmt"
import  "encoding/json"

type testStruct struct {
    clip string `json:"clip"`
}

func main() {
//unmarshal test
    var testJson = "{\"clip\":\"test\"}"
    var t testStruct
    var jsonData = []byte(testJson)
    err := json.Unmarshal(jsonData, &t)
    if err != nil {
        fmt.Printf("There was an error decoding the json. err = %s", err)
        return
    }
    fmt.Printf("contents of decoded json is: %#v\r\n", t)

//marshal test
    t.clip = "test2"
    data, err := json.Marshal(&t)
    if err != nil {
         fmt.Printf("There was an error encoding the json. err = %s", err)
         return
    }
    fmt.Printf("encoded json = %s\r\n", string(data))
}

Ausgabe:

 contents of decoded json is: main.testStruct{clip:""}
 encoded json = {}

in beiden Ausgänge, die ich erwartet hätte, um zu sehen, die dekodiert oder kodiert, json

InformationsquelleAutor Toad | 2014-08-31
Schreibe einen Kommentar