Package demo;
Import java.util.List;
Import Java.util.Map;
Import Java.util.Map.Entry;
Import Net.sf.json.JSONArray;
Import Net.sf.json.JSONObject;
public class Resolvejson {
public static void Main (string[] args) {
Jsonarray-type loading for map traversal
String jsonstr = "[{' 0 ': ' 06:00-23:00;1\\u5206\\u949f;80\\u6b65\\/\\u5206-90\\u6b65\\/\\u5206 ', ' 1 ': ' 06:00-23:00;1\ \u5206\\u949f;80\\u6b65\\/\\u5206-90\\u6b65\\/\\u5206 ', ' 2 ': ' 06:00-23:00;20\\u5206\\u949f;80\\u6b65\\/\\ u5206-90\\u6b65\\/\\u5206 '}] ";
Jsonarray array = jsonarray.fromobject (JSONSTR);
SYSTEM.OUT.PRINTLN (array);
list<map<string, object>> Maplistjson = (list<map<string, object>>) array;
for (int i = 0; i < maplistjson.size (); i++) {
map<string, object> obj = Maplistjson.get (i);
For (entry<string, object> entry:obj.entrySet ()) {
String strkey1 = Entry.getkey ();
Object Strval1 = Entry.getvalue ();
System.out.println ("KEY:" + strkey1 + "-Value:" + strval1 + "\ n");
}
}
Jsonobject-type loading for map traversal
String jsonobjectdata = "{\" 0\ ": \" 06:00-23:00;1\\u5206\\u949f;80\\u6b65\\/\\u5206-90\\u6b65\\/\\u5206\ ", \" 1\ ": \" 06:00-23:00;1\\u5206\\u949f;80\\u6b65\\/\\u5206-90\\u6b65\\/\\u5206\ ", \" 2\ ": \" 06:00-23:00;20\\u5206\\u949f;80\ \u6b65\\/\\u5206-90\\u6b65\\/\u5206\ "}";
Jsonobject jsonobject = Jsonobject.fromobject (Jsonobjectdata);
map<string, object> Mapjson = Jsonobject.fromobject (Jsonobject);
For (entry<string, object> entry:mapJson.entrySet ()) {
String strkey1 = Entry.getkey ();
Object Strval1 = Entry.getvalue ();
System.out.println ("KEY:" + entry.getkey () + "-Value:" + entry.getvalue () + "\ n");
}
}
}
JSON arrays and JSON strings converted to map parsing