java - Second JSONArray in JSONObject somehow is empty -


here's im trying do. there 2 arrays want retrieve mysql database. these 2 arrays echoed separately:

echo json_encode(array("friendrequest"=>$friendrequest)); echo json_encode(array("friendresult"=>$friendresult)); 

this code use process resulting string:

public void onresponse(string response) {         log.d("response", response);         try {              jsonobject jsonobj = new jsonobject(response);              jsonarray ja_data = jsonobj.getjsonarray("friendresult");             string[] = {                 "first_name",                 "anytimer_count",                 "relationship_status"             }; //string array             int[] = {                 r.id.textlistview1,                 r.id.textlistview2,                 r.id.textlistview3             }; //int array of views id's             jsonarrayadapter arraylistadapter = new jsonarrayadapter(myfriendsactivity.this, ja_data, r.layout.custom_list_items, from, to);             list.setadapter(arraylistadapter);               jsonarray ja_requests = jsonobj.getjsonarray("friendrequest");             int ja_lengths = ja_requests.length();             log.d("response", integer.tostring(ja_lengths));          } catch (jsonexception e) {             log.e("myfriendsactivity", "unexpected json exception", e);         } 

now, logged reponse line 2 in processing code gives me following:

response =

{   "friendrequest": [     {       "first_name": "tom",       "anytimer_count": "0",       "relationship_status": "0"     },     {       "first_name": "bert",       "anytimer_count": "0",       "relationship_status": "0"     }   ] }{   "friendresult": [     {       "first_name": "luuk",       "anytimer_count": "0",       "relationship_status": "1"     }   ] } 

this contains values should sent , correct.

the problem processing code able recognize array encoded first in php script. if swap position of 2 lines of code in php script, 'friendrequest' contain values, while 'friendresult' not , vice versa. doing wrong here?

the error im getting:

org.json.jsonexception: no value friendresult

at com.example.tomva.anytimereverywhere.myfriendsactivity$3.onresponse(myfriendsactivity.java:84)

line 84 following line:

jsonarray ja_data = jsonobj.getjsonarray("friendresult"); 

replace

echo json_encode(array("friendrequest"=>$friendrequest)); echo json_encode(array("friendresult"=>$friendresult)); 

with this

echo json_encode(array("friendrequest"=>$friendrequest,"friendresult"=>$friendresult)); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -