-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"
  ]
}
Community
  • 1
  • 1
myo htet aung
  • 107
  • 2
  • 12

3 Answers3

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

code4j
  • 4,208
  • 5
  • 34
  • 51
  • thanks for your info. is it possible to get all the datas from pages array without using `pagesArray.getString(0)`nor (1) ? – myo htet aung Oct 13 '12 at 22:33
  • 1
    you may get the length of the JSONArray by using `.length()` and iterate though the JSONArray :) – code4j Oct 14 '12 at 06:36
0

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

Asad Saeeduddin
  • 46,193
  • 6
  • 90
  • 139
  • then read [this](http://www.androidhive.info/2012/01/android-json-parsing-tutorial/) article which is the first google result for "android json parser" – Asad Saeeduddin Oct 13 '12 at 19:22
  • Rather than comment on your own answer, you can add this new information by clicking "edit". – Sam Oct 13 '12 at 19:25
  • this isn't part of my answer, it is more of a remark on the quality of the question. – Asad Saeeduddin Oct 13 '12 at 19:29
  • 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 ? – myo htet aung Oct 13 '12 at 22:37
-2

Use the JQuery function parseJSON:

var json = jQuery.parseJSON(string);
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
Aviran Cohen
  • 5,581
  • 4
  • 48
  • 75