|
Steve wang |
at Nov 8, 2013 at 2:04 pm
|
⇧ |
| |
func main() {
txt := []byte(`[{"pages": 6,"id": "ABW" },{"id": "ABW"}]`)
var objs []json.RawMessage
if err := json.Unmarshal(txt, &objs); err != nil {
fmt.Println(err)
return
}
for _, obj := range objs {
fmt.Println(string(obj))
}
}
the program above outputs:
{"pages": 6,"id": "ABW" }
{"id": "ABW"}
On Friday, November 8, 2013 9:34:18 PM UTC+8, Satish wrote:Hi,
I already tried but there is very little documentation on this.
and when I tried to use RAWMessage i am getting below error.
var x json.RawMessage = (json.(*RawMessage)).UnmarshalJSON(jsonString)
Compilation error is : "use of package json not in selector"
Thanks,
Satish
On Friday, November 8, 2013 6:52:02 PM UTC+5:30, Joshua Bleecher Snyder
wrote:
Does
http://tip.golang.org/pkg/encoding/json/#RawMessage help?
Josh
On Friday, November 8, 2013, Satish wrote:Hi,
Below is my JSON Object
Json String : `[{"pages": 6,"id": "ABW" },{"id": "ABW"}]`
when i Unmarshelled the json array, i got array of maps. i.e a[0]=
map[pages: 6,id: ABW], a[1]= map[id: ABW]
But i dont want json children objects get unmarshalled. i.e when
unmarshelled, i should get a[0]={"pages": 6,"id": "ABW" } a[1]={"id": "ABW"}
How can i avoid child json objects gettting unmarshelled.
--
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+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out. --
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+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.