-1

my php sends the following json,

[
    "x",
    "y",
    "z"
]

I am trying to parse this inside java, but I do not have a node to select from. How do I proceed ?

I am using the following:

JSONArray usernames = json.getJSONArray("What-should-i-put-here");
tony9099
  • 4,567
  • 9
  • 44
  • 73
  • Its a json Array, so simple iterate. (or provide more information) – dognose May 07 '13 at 13:05
  • yes I know that. But how to get and put it in a jsonArray in java so that I perform iteration on it. – tony9099 May 07 '13 at 13:06
  • You could convert it to a normal array as described [in this stackoverflow question.][1] and [here][2]. [1]: http://stackoverflow.com/questions/3395729/convert-json-array-to-normal-java-array [2]: http://stackoverflow.com/questions/13286176/convert-json-array-to-java-array – PHP Rocks May 07 '13 at 13:06

1 Answers1

1

What you have is a simple JSON array. It can be parsed directly with the the library you are using (JSON.org):

final String json = "[\"x\", \"y\", \"z\"]";
final JSONArray array = new JSONArray(json);
for(int i = 0; i < array.length(); i++) {
    System.out.println(array.get(i));
}
Perception
  • 79,279
  • 19
  • 185
  • 195