PHP 用Class构造JSON数据

header('Content-type: appliction/json; charset=shift-JIS');
// error
//{
//   "result":  false,
//   "message": "longin",
//   "nextUrl": "http://xxxxx/login/"
// } 
$data =array();
class Test 
{
public $id ;
public $name ;
}

for ($x=1; $x<=50; $x++) {
  $test =new Test();
  $test->id = urlencode("test".strval($x));
  $test->name= urlencode("testname");
  $data[] =$test; 
}

echo "{".'"result": true, "entrylist"'.":".urldecode(json_encode($data))."}";

  

posted @ 2016-04-13 17:57  roseforyou  阅读(413)  评论(0编辑  收藏  举报