http://code.google.com/p/json-simple/
System.out.println("=======decode=======");
String s="[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
Object obj=JSONValue.parse(s);
JSONArray array=(JSONArray)obj;
System.out.println("======the 2nd element of array======");
System.out.println(array.get(1));
JSONObject me = array.optJSONObject(0);
JSONObject fbook = new JSONObject(s);
fbook.get("namestring");
//Manage JSON String={\"4\":[5,{\"6\":7}]};
public Map parseJSONStr(String jsonText) {
JSONParser parser = new JSONParser();
ContainerFactory containerFactory = new ContainerFactory() {
public List creatArrayContainer() {
return new LinkedList();
}
public Map createObjectContainer() {
return new LinkedHashMap();
}
};
try {
Map json = (Map) parser.parse(jsonText, containerFactory);
return json;
// Iterator iter = json.entrySet().iterator();
// while(iter.hasNext()){
// Map.Entry entry = (Map.Entry)iter.next();
// }
} catch (ParseException pe) {
System.out.println(pe);
}
return null;
}
0 comments:
Post a Comment