java - How to get JSONObject values in correct / listed order? -
this question has answer here:
im using iterator<string> _names = _formobject.keys();
values following json values got not arranged in correct order ,for eg got in order of "name,no,phone,sex", how can correct values in json?
{ "form" :{ "no" : { "type" : "text" }, "phone" : { "type" : "text" }, "name" : { "type" : "text" }, "sex" : { "type" : "radio" } } }
there no "correct order" key-value pairs in json object. however, if manually process json reader, read serialized order - approach works because stream handled before reconstructed object graph (that uses map jsonobject internally).
to access raw json reader, see jsonreader - however, aware there no guarantee equivalent json supplied in order! while "will work", creates false brittleness based upon 1 (of many) equivalent json outputs.
see accepted answer in when jsonobject's keys iterated aren't in same order in response server:
the order of keys of json object not supposed meaningful. if want specific order, should use array, not object.
Comments
Post a Comment