0

I'm trying to access an API that respond with a JsonArray. The only tutorials I found was to parse the response of a JsonObject. I'm still trying to wrap-up my head around Android, I don't even understand how to call an external API.
If anybody got some tutorials or code example, I'd be really grateful !
Thanks in advance.

2 Answers 2

1

Android has a built-in JSONArray object:

JSONArray output = new JSONArray(resultFromWebService);
Sign up to request clarification or add additional context in comments.

Comments

1

If the JSONArray is very large maybe a stream based solution is better since you don't have to keep the whole object in the memory. Therefore JsonReader could be more efficient.

3 Comments

Yeah, the json will be quite big, thanks for this, I'll watch this. Can you read JsonArray with it or just JsonObject ? Cause the exemple got an ending bracket, but no beginning one.
I think this is a typo in the example, since it is not a valid Json with the messed up brackets. So if your root Json is an array (starts with []) create the Reader and use reader.beginArray(); like in the example else if it is an object (starts wit {}) use reader.beginObject();
Yeah, it seemed weird to me. Thanks a lot man, I'm gonna try that !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.