我想知道如何从此列表中提取数据。
Response
[
{
"CCTID": "46204",
"Name": "Christopher Columbus",
"CarrierId": 64239
},
{
"CCTID": "46208",
"Name": "Keith Bowles",
"CarrierId": 64239
},
{
"CCTID": "46205",
"Name": "Michael Jordan",
"CarrierId": 64239
},
{
"CCTID": "46207",
"Name": "NESV PH",
"CarrierId": 64239
}
]
如何将此数据分组到每个驱动程序并像列表一样访问以下数据。例如。司机名单。 Driver [0] [“CCTID”]返回“46204”,Driver [0] [“Name”]返回“Driver [0] [”CCTID“]返回”46204“Driver [0] [”CarrierId“]返回”64239 “等等等等。有什么想法吗?谢谢!
答案 0 :(得分:1)
试试这种方式
try {
JSONArray arr = new JSONArray(EntityUtils.toString(response.getEntity()));
for (int i = 0; i < arr.length(); i++) {
JSONObject driver = arr.getJSONObject(i);
System.out.println("CCTID : " + driver.getString("CCTID"));
System.out.println("Name : " + driver.getString("Name"));
System.out.println("CarrierId : " + driver.getString("CarrierId"));
}
} catch (Exception e) {
}