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"); 
asked May 7, 2013 at 13:31
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.

answered May 7, 2013 at 13:33
Sign up to request clarification or add additional context in comments.

Comments

2

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

Alya'a Gamal
5,64823 silver badges34 bronze badges
answered May 7, 2013 at 13:45

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.