android - Java. Praoblem with org.json -
i have json string, contain "key" : "value" pairs , need know keys @ string using java , importing org.json. tried use iterator, first pair key prints in end.
for example string:
{ "firstname": "sam", "lastname": "smith", "address": { "streetaddress": "somestreet", "city": "somecity", "postalcode": 101101 }, "phonenumbers": [ "812 123-1234", "916 123-4567" ] }
i want print: " firstname lastname address phonenumbers ". have: "lastname address phonenumbers firstname"
jsonobject jo = new jsonobject(jsonstring); iterator<string> = jo.keys(); while (it.hasnext()){ system.out.println(it.next()); }
from javadoc:
a jsonobject unordered collection of name/value pairs.
if want order keys must 1) place them in list , 2) order list according needs. keep in mind key/value representation of data - sequence of elements should not matter.
Comments
Post a Comment