This is my Json:
{"array":[
{"pid":"1","product":"test","size":[
{"id":"26","size":"6-13 weeks"},
{"id":"25","size":"1-5 weeks"}]},
{"pid":"2","product":"test2","size":[
{"id":"31","size":"86\/92"},
{"id":"27","size":"74\/80"}]}]}
I generated the files with jsongen.byingtondesign.com but I can’t seem to figure out how to get the data (I looked at lots of Tutorials but I just get more confused because they are all different.)
I need to get the data depending on pid and id. I need to output the product string with pid … or the size string with id …. (Should I restructure my json?)
Just need a few tips to get me further.
Thanks!
The structure you need is something like
and then just call
Here, I could never remember what is what. The structure looks fine, the names do not. I’d suggest something like
Now I see you’d prefer a sort of map. This is something you can do easily in Java, but you can put it into Json as well. However, you either introduce redundancy or lose the
idfrom the objects. Instead ofyou can use either
(with redundancy) or
(with the
Sizeobject missing itsid) orwhich is compact, but hardly extensible. In any case, I’d start with Java instead of Json, this makes things easier, as it’s Java you’re gonna deal with a lot. The Json string gets written and read by Gson, so you don’t need to care much how it looks like.