-1

I want to parse the simple array in a ListView. my JSON Array looks like

["Java","PHP",".NET","Python"]
2
  • 2
    Search on GOOGLE. Commented Jun 29, 2018 at 6:40
  • use for loop to loop the array and the String val = jsonarray,get(i); Commented Jun 29, 2018 at 6:44

2 Answers 2

2

Try this code..

        JSONArray jsonarray = new JSONArray(jsonStr); // define json data
    for (int i = 0; i < jsonarray.length(); i++) {
        try {
            String data = jsonarray.get(i).toString();
            Log.d("Data",data);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

0
    ListView listView = (ListView)findViewById(R.id.listView);
    ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<String>(this, 
    android.R.layout.select_dialog_item,arrayList);
    listView.setAdapter(stringArrayAdapter);

    try {
        JSONArray jsonArray = new JSONArray(str);
        for(int i = 0;i<jsonArray.length();i++)
        {
            arrayList.add(jsonArray.get(i).toString());
        }
        arrayAdapter.notifyDataSetChanged();
    } catch (JSONException e) {
        e.printStackTrace();
    }

1 Comment

str here is array value u want to parse

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.