-1

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.

3
  • that is invalid json Commented Aug 31, 2018 at 11:01
  • There was a ] missed, I added it. Commented Aug 31, 2018 at 11:03
  • 2
    Use a json library like gson then deserialize to an object that you can call a custom getter on. Commented Aug 31, 2018 at 11:06

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

5 Comments

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.
If it is array you can use for loop for that, if it is object you can access it with key name
@Hannes jsonarray is similar to normal arrays. You can use a normal for loop to iterate through it
I receive it as single array now. Should I remove [" and "] manually?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.