my array returns the following valid json.
{"usernames ":["a","b","c"]}
In Java I am trying to retrieve the value of the array by the following method. However I fail.
JSONArray usernames = json.getJSONArray("usernames");
asked May 7, 2013 at 13:31
tony9099
4,7559 gold badges48 silver badges76 bronze badges
-
Are you trying to decode from php or from java?Muhannad A.Alhariri– Muhannad A.Alhariri2013年05月07日 13:45:58 +00:00Commented May 7, 2013 at 13:45
-
try removing the space after usernamesMuhannad A.Alhariri– Muhannad A.Alhariri2013年05月07日 13:47:22 +00:00Commented May 7, 2013 at 13:47
2 Answers 2
The key ends with a space. try
JSONArray usernames = json.getJSONArray("usernames ");
EDIT: It would be better to lose the space in your php script.
answered May 7, 2013 at 13:33
Tom Dezentje
6313 silver badges16 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
remove the space in your code : "usernames " ---> "usernames"
Alya'a Gamal
5,64823 silver badges34 bronze badges
Comments
lang-java