3

I just requested a JSONObject from an URL and I wonder two things. Is a JSONObject like a JSONArray, or not? Which should I request? And is there a way to display this JSONObject somehow like var_dump in PHP? Just to check whether it worked?

Help is much appreciated! Philip

1
  • Is a JSONObject like a JSONArray, or not? => start here: json.org. Which should I request? depends on what you are requesting and what you are going to do with it. display this JSONObject-> Read doc for JSONObject.toString(); Commented Mar 21, 2014 at 18:56

2 Answers 2

6
  1. JSONObject is different from a JSONArray
  2. Just to ckeck you can invoke .toString() on your JSONObject (or JSONArray) instance.

    JSONObject jo = ...

    Log.d("TAG", jo.toString());

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

Comments

3

JSONArray is an array of JSONObjects. A JSONObject can hold one or more JSONArrays. Generally you pull a single JSONObject root node and break it up from there.

You can print the JSON by using [JSONObject#toString()][1]. You can also use JSONObject#toString(int indentSpaces) to put it in a more readable form like so:

 {
     "query": "Pizza",
     "locations": [
         94043,
         90210
     ]
 }

Comments

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.