-1

Possible Duplicate:
Sending and Parsing JSON in Android

EDIT: Finally I found an answer to get array value without key value by using Iterator. I just got an idea from this link

I am just newbie to JSON Parsing, and I have no idea how to parse this kinda JSONArray. Can anyone give me a hint ?

{

 "pages": [
      "image1.jpg",
      "image2.jpg"
  ]
}
1
  • Doesn't JSON.parse work in android? that's an array inside an object by the way. Commented Oct 13, 2012 at 19:13

3 Answers 3

1

You have to understand the basic concepts of JSON .

{} talks about an instance (called JSONObject) [] talks about an array of somethings (called JSONArray in Android) "xxx":"yyy" talks about key & value

First, you may let the reply json string become an JSONObject, JSONObject replyJSON = new JSONObject(reply)

Then, get the JSONArray named 'pages' inside the replied JSONObject, JSONArray pagesArray = replyJSON.getJSONArray("pages")

Finally, get the value inside the JSONArray by the method getString, in your example, you may use pagesArray.getString(0) and pagesArray.getString(1)

Check out the documentation for more details: JSONArray

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

2 Comments

thanks for your info. is it possible to get all the datas from pages array without using pagesArray.getString(0)nor (1) ?
you may get the length of the JSONArray by using .length() and iterate though the JSONArray :)
0

Use new JSONObject(json); where json is the variable that stores your json string.

4 Comments

then read this article which is the first google result for "android json parser"
Rather than comment on your own answer, you can add this new information by clicking "edit".
this isn't part of my answer, it is more of a remark on the quality of the question.
my problem is that i don't have Key Value in pages Array. is there any way to get the whole data from pages Array with single line of code ?
-2

Use the JQuery function parseJSON:

var json = jQuery.parseJSON(string);

2 Comments

The asker asked how to do it in android
I believe, the OP is requesting how to parse JSON in Java on Android. Not in a browser and not using jQuery.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.