Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

my php code for making a json array so far is

 $response[$x]=$row['firstname']." ".$row['lastname'];
 $res2=array("names"=>$response);
 echo json_encode($res2);

where response is an array. This has as output

{"names":["Mario 1","Luigi 2","Mario 3"]}

which looks like a json array but when i try to retrieve the array in android by using

 json.getJSONArray("names");

I get a jsonexception saying "no values for names". What is wrong? Otherwise any suggestion on how to put the names on a jsonobject and retrive them in android.?

share|improve this question

1 Answer 1

up vote 0 down vote accepted
    String obj=JSONObject.quote(YourData);
    JSONArray lArray=new JSONArray(obj);

or simply Delete the prefix 'names' $res2=array("names"=>$response); and you will retrive directelly your JsonArray like

    JSONArray lArray=new JSONArray(YouData);
share|improve this answer
    
Thanks. My code was actually correct. I made a mistake when requesting the json object. so I was not getting any object at the end. But I fixed it and I am getting the array now, going to delete this question. – user2829419 Nov 12 '13 at 23:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.