码迷,mamicode.com
首页 > Web开发 > 详细

Json数据,转换规则,

时间:2016-05-26 14:20:02      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

JSON数据转换,规则是遇见json 中的{},则是数组[],遇见name:value,则是‘key‘=>‘value‘, 但是不带键值的数组如[‘xxxxxx‘],json_encode后仍然是‘["xxxxx"]‘,若带键值,如[‘y‘=>‘xxxxxx‘],则会转换为{‘y‘:‘xxxxxxxx‘}这样的形式,完整例子,比如下面的可以相互转换,

{
   datas:[{stuid:"xxx",
      stuNo:"xxx",
      stuName:"xxx",
      completedSize:"xxx",
      uncompletedSize:"xxx"
      },
      {stuid:"xxx",
      stuNo:"xxx",
      stuName:"xxx",
      completedSize:"xxx",
      uncompletedSize:"xxx"
      }
   ],   
   page:{currpage:1,pageNo:"xxx",totals:"xxx"}
}

如果组织数据则是[

                         ‘datas‘=>[

                                        0=>[

                                                  ‘stuid‘=>‘xxxxx‘,

                                                  ‘stuNo‘=>‘xxxxxxxx‘,

                                                   ‘stuName‘=>‘xxxxxxxxxxxxx‘,

                                                   ‘completedSize=>‘xxxxxxxx‘,

                                                   ‘uncompleteSize‘=>‘xxxxxxxxxxxx‘,

                                             ],

                                          1=>[

                                                  ‘stuid‘=>‘xxxxx‘,

                                                  ‘stuNo‘=>‘xxxxxxxx‘,

                                                   ‘stuName‘=>‘xxxxxxxxxxxxx‘,

                                                   ‘completedSize=>‘xxxxxxxx‘,

                                                   ‘uncompleteSize‘=>‘xxxxxxxxxxxx‘,

                                             ]

                                         ]

                             ‘page‘=>[

                                                    currentPage=>‘1‘,

                                                    pageNo=>‘xxxx‘,

                                                    totals=>‘x‘,

                                          ]

                      ]

Json数据,转换规则,

标签:

原文地址:http://www.cnblogs.com/musings/p/5530813.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!