json数组怎么取中其中某一项
{"data":{"locations":[{"locationID":130821,"locationType":3,"parentID":130800,"nameCN...
{"data":{"locations":[{"locationID":130821,"locationType":3,"parentID":130800,"nameCN":"承德县","nameEN":"Chengde","namePinyin":"ChengDeXian","namePinyinShort":"cd","nameCode":"130821","latitude":40.97324,"longitude":118.1257,"isHot":false}]},"success":true,"errorCode":1,"errorInfo":"成功"}
展开
展开全部
public static void jsonToBean(String data) {
try {
JSONArray array = new JSONArray(data);//将json字符串转成json数组
for (int i = 0; i < array.length(); i++) {//循环json数组
JSONObject ob = (JSONObject) array.get(i);//得到json对象
String name= ob.getString("name");//name这里是列名称,获取json对象中列名为name的值
System.out.print(name);//输出name
} catch (JSONException e) {
}
}
try {
JSONArray array = new JSONArray(data);//将json字符串转成json数组
for (int i = 0; i < array.length(); i++) {//循环json数组
JSONObject ob = (JSONObject) array.get(i);//得到json对象
String name= ob.getString("name");//name这里是列名称,获取json对象中列名为name的值
System.out.print(name);//输出name
} catch (JSONException e) {
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询