How to parse JSON Array in Android?

0 votes

I have a trouble finding a way how to parse JSONArray?

 It looks like this:

[{"name":"name1","url":"url1"},{"name":"name2","url":"url2"},...]

I know how to parse it if the JSON was written differently.

There are a lot of examples out there, but they are all JSONObject related. I need something for JSONArray.

Can somebody please give me some hint?

May 26 in Java by kartik
• 15,440 points
68 views

1 answer to this question.

0 votes

Hello @kartik,

use the following snippet to parse the JsonArray.

JSONArray jsonarray = new JSONArray(jsonStr);
for (int i = 0; i < jsonarray.length(); i++) {
    JSONObject jsonobject = jsonarray.getJSONObject(i);
    String name = jsonobject.getString("name");
    String url = jsonobject.getString("url");
}

Hope it helps!!

answered May 26 by Niroj
• 32,200 points

Related Questions In Java

0 votes
3 answers

How to parse JSON in Java

import org.json.*; JSONObject obj = new JSONObject(" .... ...READ MORE

answered Aug 20, 2018 in Java by Daisy
• 8,090 points
2,154 views
0 votes
2 answers

How to create a 2-D array in java?

int[][] multi = new int[5][]; multi[0] = new ...READ MORE

answered Jul 16, 2018 in Java by Daisy
• 8,090 points
126 views
0 votes
1 answer

How to print java array in the simplest way?

String[] arr = new String[] {"John", "Mary", ...READ MORE

answered Apr 17, 2018 in Java by sophia
• 1,400 points
174 views
0 votes
3 answers

How to sort an array in java?

import java.util.Arrays; public class Sort { ...READ MORE

answered Aug 24, 2018 in Java by Parth
• 4,630 points
173 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,047 views
0 votes
0 answers
0 votes
1 answer

What are the key differences between python and java?

There are a lot of pressing  topics ...READ MORE

answered Aug 2, 2019 in Python by Mohammad
• 3,230 points
55 views
0 votes
1 answer

How to convert InputStream to byte array in Java?

Hello @kartik, You need to read each byte ...READ MORE

answered Apr 9 in Java by Niroj
• 32,200 points
1,889 views
0 votes
1 answer

How to unzip files programmatically in Android?

Hello @kartik, This is my unzip method, which ...READ MORE

answered May 25 in Java by Niroj
• 32,200 points
81 views