2

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"); 
2
  • Are you trying to decode from php or from java? Commented May 7, 2013 at 13:45
  • try removing the space after usernames Commented May 7, 2013 at 13:47

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

Comments

2

remove the space in your code : "usernames " ---> "usernames"

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.