2017-03-04 93 views

回答

0

PHP的Json编码数据

$data['postId'] = 123; 
 
$data['title'] = "Your titile"; 
 
$data['permalink'] = "http://smddtech.com"; 
 
$data['content'] = "your content"; 
 
$data['date'] = "2017-03-05"; 
 
$return['data'] = $data; 
 
echo json_encode($return); 
 
exit();

您可以凌空响应让您的数据。 See google volley documentation。请参阅下面的代码抽象JSONObject响应以及如何循环。

JSONArray newsItem=response.getJSONArray("data"); 
 
for (int loop=0;loop<newsItem.length();loop++) 
 
{ 
 
    JSONObject tempObject=newsItem.getJSONObject(loop); 
 
    int postId=tempObject.getInt("postId"); 
 
    String title=tempObject.getString("title"); 
 
    String permalink=tempObject.getString("permalink"); 
 
    String content=tempObject.getString("content"); 
 
    String date=tempObject.getString("date"); 
 
}