PHP 数组转JSON数据(convert array to JSON object);

<?php
header('Content-type: appliction/json; charset=shift-JIS');

$data =array();
class Test 
{
public  $userid ;
public $cmt ;
}

for ($x=1; $x<=50; $x++) {
  $test =new Test();
  $test->userid = urlencode("user".strval($x));
  $test->cmt = urlencode("あああああああああああああ".strval($x));
  $data[] =$test; 
}

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

?>

  

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