如何遍历JSONObject(Java json-simple)

时间:2012-03-24 11:41:01

标签: java json

我正在使用json-simple。如果我有一个JSON,如:

[
    {"id":"1","name":"...","description":"...","dtStart":"2012-03-27 03:00:00","dtEnd":"2012-03-28 03:00:00","activities":""},
    {"id":"1","name":"...","description":"...","dtStart":"2012-03-27 03:00:00","dtEnd":"2012-03-28 03:00:00","activities":""},{"id":"1","name":"...","description":"...","dtStart":"2012-03-27 03:00:00","dtEnd":"2012-03-28 03:00:00","activities":""},
    {"id":"1","name":"...","description":"...","dtStart":"2012-03-27 03:00:00","dtEnd":"2012-03-28 03:00:00","activities":""}
]

我如何迭代它?

2 个答案:

答案 0 :(得分:0)

您展示的示例属于JSONArray,因为它位于[]之间。 您应该像其他任何java Array一样遍历它。

答案 1 :(得分:0)

这将创建一个包含3个地图的列表。

for (Object o : (List)parser.parse(json)){
    Map m = (Map)o;
    //handle map
}