java解析jasonObject
re = {
"code": 0,
"holiday": {
"01-01": {
"holiday": true,
"name": "元旦",
"wage": 3,
"date": "2021-01-01",
"rest": 1
},
"01-02": {
"holiday": true,
"name": "元旦",
"wage": 2,
"date": "2021-01-02",
"rest": 1
},
"10-09": {
"holiday": false,
"name": "国庆节后调休",
"after": true,
"wage": 1,
"target": "国庆节",
"date": "2021-10-09"
}
}
}
JSONObject.parseObject(re.getContent()).getJSONObject("holiday");
Iterator iter = body.entrySet().iterator();
List<HolidayEntity> dayList = new ArrayList<>();
while(iter.hasNext()) {
Map.Entry entry = (Entry) iter.next();
JSONObject holidayInfo = (JSONObject) entry.getValue();
System.out.println(holidayInfo.getString("holiday"));
}
java解析JSONArray
JSONObject body = JSONObject.parseObject(result.getContent());
JSONArray users = body.getJSONArray("userlist");
for (int i = 0; i < users.size(); i++) {
System.out.println( ((JSONObject)users.get(i)).getString("userid"));
}