求助:格式化这样的一个json串,语法该怎么写?(急!)
例如有一个二维数组
$myarrnews=array();
$myarrnews =explode(||**||, $mystr); //内容来自$mystr,包括多条新闻记录
$myarrline=array();
$myarrline =explode(||%%||, $myarrnews[$i]); //$myarrline 是其中的一条记录,包括多个字段
print_r($myarrline); //每个新闻各个字段的集合,例如:array ( [0] => 10 [1] => 2166 [2] => 创新。。。
现在需要这样的一个json串,格式为:(暂时设定为每页显示5条)
{
ret: 0,
data: {
newslist: [
{
title: 第1条新闻标题,
commentcount: 0,
source: 来源,
nid: 10,
digest: 新闻简介,
ptime: 2012-03-28 14:11:43
},
{
title: 第2条新闻标题,
commentcount: 0,
source: 来源,
nid: 9,
digest: 新闻简介,
ptime: 2012-03-28 13:12:56
},
{
title: 第3条新闻标题,
commentcount: 0,
source: 来源,
nid: 8,
digest: 新闻简介,
ptime: 2012-03-28 12:21:11
},
{
title: 第4条新闻标题,
commentcount: 0,
source: 来源,
nid: 7,
digest: 新闻简介,
ptime: 2012-03-28 11:21:00
},
{
title: 第5条新闻标题,
commentcount: 1,
source: 来源,
nid: 5,
digest: 新闻简介,
ptime: 2012-02-18 19:20:01
}
],
totalnum: 5
},
msg: ok
}
//----------------------------
php语法该如何书写呢?请大家帮忙,急用!
------解决方案--------------------
$ar = arrat(
' ret' => 0,
'data' => array(
'newslist' => $newslist,