-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");
3
  • Its a json Array, so simple iterate. (or provide more information) Commented May 7, 2013 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. Commented May 7, 2013 at 13:06
  • You could convert it to a normal array as described [in this stackoverflow question.][1] and [here][2]. [1]: stackoverflow.com/questions/3395729/… [2]: stackoverflow.com/questions/13286176/… Commented May 7, 2013 at 13:06

1 Answer 1

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));
}
Sign up to request clarification or add additional context in comments.

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.