tony9099
tony9099

Reputation: 4717

can not parse json array from php

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"); 

Upvotes: 2

Views: 189

Answers (2)

Numb Gk
Numb Gk

Reputation: 51

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

Upvotes: 2

Tom Dezentje
Tom Dezentje

Reputation: 631

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.

Upvotes: 8

Related Questions