Home > Backend Development > PHP Tutorial > 格式化这样的一个json串,语法该如何写?(急)

格式化这样的一个json串,语法该如何写?(急)

WBOY
Release: 2016-06-13 11:52:11
Original
903 people have browsed it

求助:格式化这样的一个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(<br>  ' ret' => 0, <br>  'data' => array(<br>     'newslist' => $newslist,<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template