我得到2,3 & 4個字符串(值)在數組中,但我無法在textview中設置值。我得到的TextView的是隻有4個值也相同repeat.Please告訴我如何處理下面this.JSON:無法從JsonArray獲取字符串
{
results: [
{
types: [
"sublocality_level_3",
"sublocality",
"political"
]
},
{
types: [
"point_of_interest",
"establishment"
]
},
{
types: [
"travel_agency",
"point_of_interest",
"establishment"
]
},
{
types: [
"point_of_interest",
"establishment"
]
},
{
types: [
"store",
"point_of_interest",
"establishment"
]
},
{
types: [
"dentist",
"health",
"point_of_interest",
"establishment"
]
},
{
types: [
"clothing_store",
"store",
"point_of_interest",
"establishment"
]
},
{
types: [
"point_of_interest",
"establishment"
]
},
]
}
碼是什麼我想:
try {
object = new JSONObject(url);
JSONArray array = object.getJSONArray("results");
for (int i = 0; i < array.length(); i++){
JSONObject object1 = array.getJSONObject(i);
JSONArray array1 = object1.getJSONArray("types");
for(int j = 0; j < array1.length(); j++){
if (array1.length()==2) {
t1 = array1.getString(0);
t2 = array1.getString(1);
} if (array1.length()==3) {
t1 = array1.getString(0);
t2 = array1.getString(1);
t3 = array1.getString(2);
} if (array1.length()==4) {
t1 = array1.getString(0);
t2 = array1.getString(1);
t3 = array1.getString(2);
t4 = array1.getString(3);
}
}
getterSetter.setT1(t1);
getterSetter.setT2(t2);
getterSetter.setT3(t3);
getterSetter.setT4(t4);
list.add(getterSetter);
adapter = new GooglePlacesAdapter(GooglePlace.this,list);
listView.setAdapter(adapter);
}
} catch (JSONException e) {
e.printStackTrace();
}
什麼是你所面臨的問題? – Rohit5k2
我無法得到字符串,它是類型arraylist中的2和3 – AndroidLover
重新編輯您的問題。您的JSON文件無效。 [請首先閱讀此鏈接](http://www.json.org/) – Bonatti