JSON-简单示例
private static String jsonText = "{\"first\": \"ali\", \"second\":" +
" [4, 5, 6], \"third\": 789},{\"first\": \"saeed\", \"second\":" +
" [10, 7, 8], \"third\": 1000},{\"first\": \"reza\", \"second\":" +
" [14, 15, 16], \"third\": 999}";
public static void main(String args[])
throws org.json.simple.parser.ParseException {
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);
Iterator iter = json.entrySet().iterator();
System.out.println("==iterate result==");
while(iter.hasNext()) {
Map.Entry entry = (Map.Entry)iter.next();
System.out.println(entry.getKey() + "=>" + entry.getValue());
}
System.out.println("==toJSONString()==");
System.out.println(JSONValue.toJSONString(json));
} catch(ParseException pe) {
System.out.println(pe);
}
}
这抛出一个异常
Unexpected token COMMA(,) at position 51.
是三条记录的jsonText
内容,怎么读取三条记录?