这是 Json 文件。
{
"paging": {
"next_offset": 100,
"total": 247,
"limit": 100
},
"body_stats": [
{
"weight": 208.0,
"id": "13500547638911",
"date": "2012-10- 12T15:12:50Z",
"user_id": "13499829320503",
"bmr": 2723.328,
"bmi": 28.2067901234568
},
{
"resting_heart_rate": 65.0,
"weight": 135.0,
"id": "1b5kegg00 00js2p5pfmg000000",
"date": "2013-04- 15T00:44:12Z",
"user_id": "13589643116210",
"girths": {
"abdomen": 30.0,
"waist": 30.0
}
}
]
}
我想从这个 json 中读取值,
try{
Object obj = parser.parse(new FileReader("D:/jdemo.json"));
JSONObject jsonObject = (JSONObject) obj;
JSONArray companyList = (JSONArray)jsonObject.get("body_stats");
Iterator<Object> iterator = companyList.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
输出:
{
"id": "13500547638911",
"bmr": 2723.328,
"weight": 208.0,
"bmi": 28.2067901234568,
"user_id": "13499829320503",
"date": "2012-10-12T15:12:50Z"
},
{
"id": "1b5kegg0000js2p5pfmg000000",
"weight": 135.0,
"girths": {
"abdomen": 30.0,
"waist": 30.0
},
"user_id": "13589643116210",
"date": "2013-04-15T00:44:12Z",
"resting_heart_rate": 65.0
}
但是我想从中读取"girths"{" ",""}
如何读取girths{}
值?