Ich war Marshaling ein Unmarshalling JSONs mit Golang und wenn ich es mit Zahlenfeldern tun will, wandelt Golan es in Gleitkommazahlen anstelle von langen Zahlen, zum Beispiel.JSON Marshalling mit langen Zahlen in Golang, gibt Gleitkommazahl
Ich habe folgende JSON:
{
"id": 12423434,
"Name": "Fernando"
}
Nachdem es Marschall auf eine Karte und Abstellungs wieder auf ein JSON-String erhalte ich:
{
"id":1.2423434e+07,
"Name":"Fernando"
}
Wie Sie das Feld „ID“ zu sehen ist in Fließkomma-Notation.
Der Code, den ich verwende ist die folgende:
package main
import (
"encoding/json"
"fmt"
"os"
)
func main() {
//Create the Json string
var b = []byte(`
{
"id": 12423434,
"Name": "Fernando"
}
`)
//Marshal the json to a map
var f interface{}
json.Unmarshal(b, &f)
m := f.(map[string]interface{})
//print the map
fmt.Println(m)
//unmarshal the map to json
result,_:= json.Marshal(m)
//print the json
os.Stdout.Write(result)
}
Er druckt: Karte [ID: 1.2423434e + 07 Name: Fernando] { "Name": "Fernando", "id" : 1.2423434e + 07}
Es scheint zu sein, dass der erste Marshalel auf der Karte das FP generiert. Wie kann ich es zu lange beheben?
Dies ist der Link zu dem Programm in dem Goland Spielplatz: http://play.golang.org/p/RRJ6uU4Uw-
Fer
Sie Marschall nicht in eine 'Karte [string] Schnittstelle {}' aber eine richtige Struktur mit z.B. ein 'int64'-Feld für 'id'. – Volker