this

解析 Jason数据

/**
* <pre>
* {
* "id": 2,
* "title": "json title",
* "config": {
* "width": 34,
* "height": 35
* },
* "data": [
* "JAVA",
* "JavaScript",
* "PHP"
* ]
* }
* </pre>
*
* @param args
*/
public static void main(String[] args)
{
System.out.println("----------------------------");
String jsonStr = "{\"id\": 2," + " \"title\": \"json title\", " + "\"config\": {" + "\"width\": 34,"
+ "\"height\": 35," + "}, \"data\": [" + "\"JAVA\", \"JavaScript\", \"PHP\"" + "]}";
System.out.println(jsonStr);
System.out.println("----------------------------");
JSONObject ob = JSONObject.parseObject(jsonStr);
Set<String> obKeys = ob.keySet();

for (String key : obKeys)
{
System.out.println(key + " : " + ob.getString(key));

}
System.out.println("----------------------------");
// System.out.println(ob.values());

JSONObject config = (JSONObject) ob.get("config");
Set<String> configKeys = config.keySet();

for (String key : configKeys)
{
System.out.println(key + " : " + config.getByteValue(key));

}
System.out.println("----------------------------");
JSONArray array = (JSONArray) ob.get("data");
ListIterator<Object> it = array.listIterator();
while (it.hasNext())
{
System.out.println(it.next());
}
System.out.println("----------------------------");
}

 

posted @ 2014-12-02 17:34  湖南司马懿  Views(242)  Comments(0Edit  收藏  举报