I want to parse JSON which looks like this:
{
"A": [
[
"content1"
],
[
"content2"
]
]
}
I need content1 and content2 as a String.
What I tried
String content = object.getString("A");
but with this I get a String which includes content1 and content2.
I need it seperated because I add it to GridView later.
This is not a duplicate of the question which is marked, look at the JSON it is different.
asked Aug 31, 2018 at 11:00
Hannes
2231 gold badge3 silver badges9 bronze badges
1 Answer 1
It should be object.getJSONArray("A"), store it in some variable.
JSONArray someArray = object.getJSONArray("A");
and than you can traverse through JSONArray to get its values
answered Aug 31, 2018 at 11:05
Ravi
35.7k22 gold badges127 silver badges188 bronze badges
Sign up to request clarification or add additional context in comments.
5 Comments
Hannes
Okay but I have to define [0] [1] etc? The problem is there can be a lot of Arrays and not only one or two.
Ravi
If it is array you can use for loop for that, if it is object you can access it with
key nameVivek Mishra
@Hannes jsonarray is similar to normal arrays. You can use a normal for loop to iterate through it
AskNilesh
@Hannes check this stackoverflow.com/a/30586115/7666442
Hannes
I receive it as single array now. Should I remove
[" and "] manually?lang-java
]missed, I added it.