我已经尝试过,但似乎无法深入了解它。这是PHP代码
$query = "SELECT `title` FROM `c2torsdb`.`pE_vacancies` WHERE active=1 LIMIT 2";
$result = mysql_query($query,$link) or die('Errant query: '.$query);
/* create one master array of the 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);
}
这是我的代码片段
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 + " - ");
这是 PHP 脚本的 JSON 输出:
[{"post":{"title":"Property Litigation Assistant Solicitor"}},{"post":{"title":"Trusts and Probate Practitioner"}}]
我只想要“标题”。