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");
asked May 7, 2013 at 13:01
tony9099
4,7559 gold badges48 silver badges76 bronze badges
-
Its a json Array, so simple iterate. (or provide more information)dognose– dognose2013年05月07日 13:05:18 +00:00Commented 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.tony9099– tony90992013年05月07日 13:06:10 +00:00Commented 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/…PHP Rocks– PHP Rocks2013年05月07日 13:06:27 +00:00Commented May 7, 2013 at 13:06
1 Answer 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));
}
answered May 7, 2013 at 13:49
Perception
80.8k19 gold badges190 silver badges197 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default