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, 2020 in Java by kartik
• 37,520 points
7,850 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, 2020 by Niroj
• 82,880 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,140 points
3,997 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,140 points
1,476 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
824 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,640 points
1,165 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,396 views
0 votes
1 answer
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
676 views
0 votes
2 answers

How to convert InputStream to byte array in Java?

The class IOUtils, lib: https://mvnrepository.com/artifact/com ...READ MORE

answered Sep 24, 2020 in Java by Anthony
15,550 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, 2020 in Java by Niroj
• 82,880 points
6,218 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP