使用前需要导入## gson-2.2.4
public static void main(String[] args) {
try {
JsonParser parser=new JsonParser(); //解析器
JsonObject object=(JsonObject) parser.parse(new FileReader("json.json"));
JsonArray array=object.getAsJsonArray("数据1").getAsJsonArray();
for(int i=0;i<array.size();i++) {
System.out.println("---------");
JsonObject subObject=array.get(i).getAsJsonObject();
System.out.println(subObject.get("id").getAsString());
}
} catch (JsonIOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonSyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
{
"cat":"it",
"数据1":
[
{"id":1,"ide":"Eclipse","name":"java"},
{"id":2,"ide":"Eclipse2","name":"java2"},
{"id":3,"ide":"Eclipse3","name":"java3"}
],
"pop":true
}