-1
我有奇怪的情況,我不知道如何將此json響應綁定到spinner。 我實現這種方式,但沒有成功所有value.please建議或幫助我綁定它。將不同的json綁定到spinner
JSON響應
{
"data": [
{
"gujarati": "Gujarati",
"english": "English",
"hindi": "Hindi",
"hebrew": "Hebrew",
"french": "French",
"spanish": "Spanish",
"arabic": "Arabic",
"polish": "Polish",
"bulgarian": "Bulgarian",
"dude": "Dude",
"all of them": "All Of Them",
"uk english": "Uk English"
}
]
}
附加由鍵列出。
try {
root = new JSONObject(resplanguage);
JSONArray contacts = root.getJSONArray("data");
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
languagelist.add(new LanguageData(c.getString("gujarati"), c.getString("english"), c.getString("hindi"),
c.getString("hebrew"), c.getString("french"), c.getString("spanish"), c.getString("arabic"),
c.getString("polish"), c.getString("bulgarian"), c.getString("dude"), c.getString("all of them"),
c.getString("uk english")));
}
} catch (Exception e) {
e.printStackTrace();
}
與微調器結合。
for (int k=0;k<languagelist.size();k++){
englisins[k]= String.valueOf(languagelist.get(k));
}
englishadapter= new ArrayAdapter<String>(ExploreInstructorActivity.this,
android.R.layout.simple_spinner_item, englisins);
englishadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spEnglishSpeaking.setAdapter(englishadapter);
你得到的JSON數據沒有問題,你可以添加你用來獲取數據的方式。 –
確保languagelist是外部JSON對象內數據數組的第一個索引對象,而不是JSON對象jnstead。 –
我不是成功添加所有字符串@ Brunoferreira –