Online to find a lot of methods are level, because the need for multilevel map, so do the following package
public static map<string, object> Parsejson2map (String jsonstr) {
Outermost parsing
if (Jsonstr!=null&&jsonstr.startswith ("{") &&jsonstr.endswith ("}")) {
map<string, object> map = new hashmap<string, object> ();
Jsonobject json = Jsonobject.fromobject (JSONSTR);
For (Object K:json.keyset ()) {
Object v = json.get (k);
If the inner layer is still an array, continue parsing
if (v instanceof jsonarray) {
list<map<string, object>> list = new arraylist<map<string,object>> ();
Iterator<jsonobject> it = ((Jsonarray) v). Iterator ();
while (It.hasnext ()) {
Jsonobject Json2 = It.next ();
List.add (Parsejson2map (json2.tostring ()));
}
Map.put (k.tostring (), list);
} else {
Map<string, object> m = Parsejson2map (V.tostring ());
if (m==null)
Map.put (K.tostring (), v);
Else
Map.put (K.tostring (), m);
}
}
return map;
}else{
return null;
}
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
JSON string converted to multi-level map-list-map form