将不同的json绑定到微调器

时间:2017-07-30 17:34:38

标签: android json spinner

我有奇怪的情况我不知道如何将这个json响应绑定到微调器。 我实现这种方式,但没有获得成功所有的价值。请建议或帮助我绑定它。

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);

1 个答案:

答案 0 :(得分:0)

您再次无法访问数组中的JSON对象。试试这个,让我知道:

k