java - Iterate json from first to last element -


i getting data json order of appearance important. is, element @ index 0 should literally come before element @ index 1 , on.

using snippet below iterate through json (the keys of each object used also.)

jsonobject jobject = new jsonobject(string);             iterator<string> keys = jobject.keys();             node = doc.createelement("ul");             while (keys.hasnext()) {                 string _keys = (string) keys.next();                 system.out.println(_keys); //other codes here} 

the problem not visit json object first last. have tested sample json , found out order can not determined. there way can achieve ?

a json object has no order of members, definition. if order important, use array, if order alphabetic, sort keys , iterate on sorted list.


Comments