[{ “类别”:“地址”, “AddressDetail”:[{ “标题”:“Dunya Ticaret Merkezi”, “手机”: “747”, “纬度”:“39.903712”, “经度”:“32.865229” },{ “标题”:“Tepe Prime”, “手机”: “737”, “纬度”:“39.910020”, “经度”:“32.755583” }] }]
答案 0 :(得分:0)
我的代码是......像这样,如何改变正确的形式?
String strJson =“{[{\”Category \“:\”Addresses \“,\”AddressDetail \“:[{\”Title \“:\”Dunya Ticaret Merkezi \“,” +“\”Phone \“:\”747 \“,\”Latitude \“:\”39.903712 \“,\”经度\“:\”32.865229 \“},” +“{\”Title \“:\”Tepe Prime \“,\”Phone \“:\”737 \“,\”Latitude \“:\”39.910020 \“,\”经度\“:\”32.755583 \ “}]}]}”;
String data = "";
try {
JSONObject jsonObj = new JSONObject(strJson);
JSONArray jarRow = jsonObj.getJSONArray("Category");
for(int i=0;i<jarRow.length(); i++){
// creating an object first
JSONObject ElementsObj = jarRow.getJSONObject(i);
// and getting the array out of the object
JSONArray jarElements = ElementsObj.getJSONArray("AddressDetail");
for(int j=0; j<jarElements.length(); j++){
JSONObject distanceObj = jarElements.getJSONObject(j).getJSONObject("distance");
String distanceStr = distanceObj.getString("Title");
int Phone = distanceObj.getInt("Phone");
Log.v("finally getting distance : ", distanceStr);
}
}
} catch (JSONException e) {
e.printStackTrace();
}