Re: [go-nuts] Issue using json with array
Thanks Tomás! now reading info about Marshal El sábado, 2 de febrero de 2019, 20:24:36 (UTC-3), Tomás González Dowling escribió: > > Not sure if that was a question, Juan. But you can use Marshal method in > the encoding/json package to avoid using make. There are some examples in > the official docs: https://golang.org/pkg/encoding/json/#example_Marshal > > Hope that it helps :) > > El mié., 19 dic. 2018 a las 9:44, Juan Mamani ( >) escribió: > >> Thanks a lot for your reply!! You are right it's working. >> >> But, it could be possible to avoid calling "make"... >> >> El mié., 19 de dic. de 2018 a la(s) 08:14, Ozone Kawakami ( >> kawakam...@gmail.com ) escribió: >> >>> Your code `make(pos, 1)` seems to be typo. >>> The fixed version works well. >>> https://play.golang.org/p/gnLe_Xi2-nb >>> >>> 2018年12月19日(水) 10:40 Juan Mamani >: >>> I'm not an expert but I do my best. Original json format required: { "pos": [{ "lp" : "WISE-12", "lat": "-33,43565400", "lon" : "-70,60552700", "speed" : "102" }] } Json autogenerated from: https://mholt.github.io/json-to-go/ (lazy style but it works. Even more when my boss is surrounding like a shark! jajaa) type AutoGenerated struct { Pos []struct { Lp string `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` Speed string `json:"speed"` } `json:"pos"` } So I tried more fancy style but it doesn´t work:( type track struct{ Lp string `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` Speed string `json:"speed"` } type pos struct{ Position []track `json:"pos"` } x := pos{ Position:[{Lp:"DEMO" , Lat:"-33.3244",Lon:"-33.391134",Speed:"80", } ]} Somebody gave me a hand with this: track := make(pos,1) track[0].Lp = "EEE" track[0].Lat = "-23.243423" track[0].Lon = "-24.2344123" track[0].Speed = "50" Data2Send := pos{track} But it doesn't keep "pos" when I check Data2Send with fmt.Printf("%v",Data2Send). Any idea? "Is any out there?" Thanks -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com . For more options, visit https://groups.google.com/d/optout. >>> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Tomás González Dowling | Comtom Tech > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Issue using json with array
Not sure if that was a question, Juan. But you can use Marshal method in the encoding/json package to avoid using make. There are some examples in the official docs: https://golang.org/pkg/encoding/json/#example_Marshal Hope that it helps :) El mié., 19 dic. 2018 a las 9:44, Juan Mamani () escribió: > Thanks a lot for your reply!! You are right it's working. > > But, it could be possible to avoid calling "make"... > > El mié., 19 de dic. de 2018 a la(s) 08:14, Ozone Kawakami ( > kawakami.oz...@gmail.com) escribió: > >> Your code `make(pos, 1)` seems to be typo. >> The fixed version works well. >> https://play.golang.org/p/gnLe_Xi2-nb >> >> 2018年12月19日(水) 10:40 Juan Mamani : >> >>> I'm not an expert but I do my best. >>> >>> Original json format required: >>> { "pos": [{ "lp" : "WISE-12", "lat": "-33,43565400", "lon" : >>> "-70,60552700", "speed" : "102" }] >>> } >>> >>> Json autogenerated from: https://mholt.github.io/json-to-go/ (lazy >>> style but it works. Even more when my boss is surrounding like a shark! >>> jajaa) >>> >>> type AutoGenerated struct { Pos []struct { Lp string >>> `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` >>> Speed string `json:"speed"` } `json:"pos"` } >>> >>> So I tried more fancy style but it doesn´t work:( >>> >>> type track struct{ Lp string `json:"license_plate"` Lat string >>> `json:"lat"` Lon string `json:"lon"` >>> Speed string `json:"speed"` >>> } type pos struct{ Position []track `json:"pos"` } >>> >>> x := pos{ Position:[{Lp:"DEMO" , >>> Lat:"-33.3244",Lon:"-33.391134",Speed:"80", } ]} >>> >>> Somebody gave me a hand with this: >>> >>> track := make(pos,1) >>> track[0].Lp = "EEE" >>> track[0].Lat = "-23.243423" >>> track[0].Lon = "-24.2344123" >>> track[0].Speed = "50" >>> >>> Data2Send := pos{track} >>> >>> But it doesn't keep "pos" when I check Data2Send with >>> fmt.Printf("%v",Data2Send). >>> Any idea? "Is any out there?" >>> >>> Thanks >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "golang-nuts" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to golang-nuts+unsubscr...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Tomás González Dowling | Comtom Tech -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Issue using json with array
Your code `make(pos, 1)` seems to be typo. The fixed version works well. https://play.golang.org/p/gnLe_Xi2-nb 2018年12月19日(水) 10:40 Juan Mamani : > I'm not an expert but I do my best. > > Original json format required: > { "pos": [{ "lp" : "WISE-12", "lat": "-33,43565400", "lon" : > "-70,60552700", "speed" : "102" }] > } > > Json autogenerated from: https://mholt.github.io/json-to-go/ (lazy style > but it works. Even more when my boss is surrounding like a shark! jajaa) > > type AutoGenerated struct { Pos []struct { Lp string > `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` > Speed string `json:"speed"` } `json:"pos"` } > > So I tried more fancy style but it doesn´t work:( > > type track struct{ Lp string `json:"license_plate"` Lat string > `json:"lat"` Lon string `json:"lon"` > Speed string `json:"speed"` > } type pos struct{ Position []track `json:"pos"` } > > x := pos{ Position:[{Lp:"DEMO" , > Lat:"-33.3244",Lon:"-33.391134",Speed:"80", } ]} > > Somebody gave me a hand with this: > > track := make(pos,1) > track[0].Lp = "EEE" > track[0].Lat = "-23.243423" > track[0].Lon = "-24.2344123" > track[0].Speed = "50" > > Data2Send := pos{track} > > But it doesn't keep "pos" when I check Data2Send with > fmt.Printf("%v",Data2Send). > Any idea? "Is any out there?" > > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Issue using json with array
Thanks a lot for your reply!! You are right it's working. But, it could be possible to avoid calling "make"... El mié., 19 de dic. de 2018 a la(s) 08:14, Ozone Kawakami ( kawakami.oz...@gmail.com) escribió: > Your code `make(pos, 1)` seems to be typo. > The fixed version works well. > https://play.golang.org/p/gnLe_Xi2-nb > > 2018年12月19日(水) 10:40 Juan Mamani : > >> I'm not an expert but I do my best. >> >> Original json format required: >> { "pos": [{ "lp" : "WISE-12", "lat": "-33,43565400", "lon" : >> "-70,60552700", "speed" : "102" }] >> } >> >> Json autogenerated from: https://mholt.github.io/json-to-go/ (lazy style >> but it works. Even more when my boss is surrounding like a shark! jajaa) >> >> type AutoGenerated struct { Pos []struct { Lp string >> `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` >> Speed string `json:"speed"` } `json:"pos"` } >> >> So I tried more fancy style but it doesn´t work:( >> >> type track struct{ Lp string `json:"license_plate"` Lat string >> `json:"lat"` Lon string `json:"lon"` >> Speed string `json:"speed"` >> } type pos struct{ Position []track `json:"pos"` } >> >> x := pos{ Position:[{Lp:"DEMO" , >> Lat:"-33.3244",Lon:"-33.391134",Speed:"80", } ]} >> >> Somebody gave me a hand with this: >> >> track := make(pos,1) >> track[0].Lp = "EEE" >> track[0].Lat = "-23.243423" >> track[0].Lon = "-24.2344123" >> track[0].Speed = "50" >> >> Data2Send := pos{track} >> >> But it doesn't keep "pos" when I check Data2Send with >> fmt.Printf("%v",Data2Send). >> Any idea? "Is any out there?" >> >> Thanks >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Issue using json with array
I'm not an expert but I do my best. Original json format required: { "pos": [{ "lp" : "WISE-12", "lat": "-33,43565400", "lon" : "-70,60552700", "speed" : "102" }] } Json autogenerated from: https://mholt.github.io/json-to-go/ (lazy style but it works. Even more when my boss is surrounding like a shark! jajaa) type AutoGenerated struct { Pos []struct { Lp string `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` Speed string `json:"speed"` } `json:"pos"` } So I tried more fancy style but it doesn´t work:( type track struct{ Lp string `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` Speed string `json:"speed"` } type pos struct{ Position []track `json:"pos"` } x := pos{ Position:[{Lp:"DEMO" , Lat:"-33.3244",Lon:"-33.391134",Speed:"80", } ]} Somebody gave me a hand with this: track := make(pos,1) track[0].Lp = "EEE" track[0].Lat = "-23.243423" track[0].Lon = "-24.2344123" track[0].Speed = "50" Data2Send := pos{track} But it doesn't keep "pos" when I check Data2Send with fmt.Printf("%v",Data2Send). Any idea? "Is any out there?" Thanks -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.