Extracting JSON from PHP on Android -
i have tried , tried , can't seem bottom of it. here php code
$query = "select `title` `c2torsdb`.`pe_vacancies` active=1 limit 2"; $result = mysql_query($query,$link) or die('errant query: '.$query); /* create 1 master array of records */ $posts = array(); if(mysql_num_rows($result)) { while($post = mysql_fetch_assoc($result)) { $posts[] = array('post'=>$post); } } /* output in necessary format */ if($format == 'json') { header('content-type: application/json, charset=utf-8'); echo json_encode($posts); }
and here code snippet
httpresponse response = httpclient.execute(httppost); string jsonresult = inputstreamtostring(response.getentity().getcontent()).tostring(); jsonobject object = new jsonobject(jsonresult); //jsonarray innerobj = object.getjsonarray("post"); string name = object.getstring("title"); //string name = name1.getstring(0); log.v("isurgeon", name); //string name = object.getstring("posts"); //string verion = object.getstring("version"); textview.settext(name + " - ");
here json output php script:
[{"post":{"title":"property litigation assistant solicitor"}},{"post":{"title":"trusts , probate practitioner"}}]
i want 'title'.
i honest, not familiar android know json. if take json output , place javascript this:
var abc = [{"post":{"title":"property litigation assistant solicitor"}},{"post":{"title":"trusts , probate practitioner"}}]
i 1st title doing this:
abc[0].title
you need select nth element of returned json object title.
Comments
Post a Comment