例子:
{
"usersInfo": [
{
"winrate": 0.41666666,
"userid": "40288ac35287986001528799f7db0007",
"name": "zhenyue",
"money": 10110,
"avatar": "97.jpg"
},
{
"winrate": 0.47368422,
"userid": "40288ac35287986001528799c5a80005",
"name": "zehao",
"money": 10880,
"avatar": "97.jpg"
}
],
"houseInfo": {
"houseId": "40285281547fa17f01547fcc5c1208e1",
"isHost": false,
"houseName": "678",
"baseMoney": 80,
"hostName": "zhenyue",
"userNum": 2,
"status": 2
},
"Flag": true,
"nextFlag": false
}
1、以上json数据为:
2、获得对象数组"usersInfo":
JSONArray json_users = jsonObject1.getJSONArray("usersInfo");
for (int i = 0; i < json_users.length(); i++) { JSONObject jsonObject2 = json_users.getJSONObject(i); User user2 = new User(); user2.setId(jsonObject2.getString("userid")); user2.setMoney(jsonObject2.getString("money")); user2.setName(jsonObject2.getString("name")); System.out.println("username===="+user2.getName()); users.add(user2); }
3、获得对象"houseInfo":
JSONObject json_celldata = jsonObject1.getJSONObject("houseInfo");
celldata.setTitle(json_celldata.getString("houseName")); celldata.setId(json_celldata.getString("houseId")); celldata.setMinscore(json_celldata.getString("baseMoney")); celldata.setNum(json_celldata.getString("userNum")); celldata.setStatus(json_celldata.getString("status"));
4、获得Boolean型数据"nextFlag":
nextFlag=jsonObject1.getBoolean("nextFlag");