How to write the syntax for formatting such a json string? (Urgent)

Source: Internet
Author: User
How to write the syntax for formatting such a json string? (Urgent !) For example, there is a two-dimensional array & nbsp; $ myarrnewsarray (); $ myarrnews & nbsp; explode (| ** |, & nbsp; $ mystr); & nbsp; content comes from $ mystr, including multiple News records $ myarrlinearray (); & nbsp; $ myarrline & nbs help: how to write the syntax to format such a json string? (Urgent !)
For example, there is a two-dimensional array
$ Myarrnews = array ();
$ Myarrnews = explode ("| ** |", $ mystr); // the content comes from $ mystr, including multiple news Records.
$ Myarrline = array ();
$ Myarrline = explode ("| |%%| |", $ myarrnews [$ I]); // $ myarrline is one of the records, including multiple fields
Print_r ($ myarrline); // A set of fields for each news, for example, Array ([0] => 10 [1] => 2166 [2] => innovation...
Now we need a json string in the format of: (set to display 5 entries per page)
{
"Ret": 0,
"Data ":{
"Newslist ":[
{
"Title": "1st News Headlines ",
"Commentcount": 0,
"Source": "source ",
"Nid": 10,
"Digest": "News Introduction ",
"Ptime": "14:11:43"
},
{
"Title": "2nd News Headlines ",
"Commentcount": 0,
"Source": "source ",
"Nid": 9,
"Digest": "News Introduction ",
"Ptime": "13:12:56"
},
{
"Title": "3rd News Headlines ",
"Commentcount": 0,
"Source": "source ",
"Nid": 8,
"Digest": "News Introduction ",
"Ptime": "12:21:11"
},
{
"Title": "4th News Headlines ",
"Commentcount": 0,
"Source": "source ",
"Nid": 7,
"Digest": "News Introduction ",
"Ptime": "11:21:00"
},
{
"Title": "5th News Headlines ",
"Commentcount": 1,
"Source": "source ",
"Nid": 5,
"Digest": "News Introduction ",
"Ptime": "19:20:01"
}
],
"Totalnum": 5
},
"Msg": "OK"
}
//----------------------------
How should I write the php syntax? Please help. please try again!
------ Solution --------------------
$ar = arrat(
' ret' => 0,
'data' => array(
'newslist' => $newslist,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.