sabish
sabish

Reputation: 31

How to store Json Array to Java ArrayList?

I am completely don't know Json. Now i am working in Android project. I know how to use ArrayList. I have Json file inside of my Asset folder in my Android Project.

So, now i need How to parse this file from assets folder and how to store it to ArrayList.

Upvotes: 0

Views: 5433

Answers (1)

dn_c
dn_c

Reputation: 614

String json="Your Json";
JSONObject resultJson = new JSONObject(json);
JSONArray value = resultJson.getJSONArray(<Pass Your JsonOject Key here>);
ArrayList<String> list = new ArrayList<>();

for (int i = 0; i < value.length(); i++)
{
    JSONObject qstnArray = value.getJSONObject(i);
    list.add(qstnArray.getString("question"));                  
}

Upvotes: 4

Related Questions