【问题标题】:how to Create Json in Php如何在 PHP 中创建 Json
【发布时间】:2017-05-23 14:01:20
【问题描述】:

如何在 PHP 中创建这样的 Json?

[
 [
  "16226281",
   "11",
   "Disclosure.1994.720p.BluRay.H264.AAC-RARBG",
   "finished"
  ],
  [ 
   "16226038",
   "140",
   "Courage The Cowardly Dog (1999-2002)",
   "finished"
  ],
  [
   "16226020",
   "101",
   "[R.G. Mechanics] Call of Duty 4 Modern Warfare",
   "finished"
  ]
]

我在互联网上搜索了很多,但没有得到任何结果。

【问题讨论】:

标签: php json


【解决方案1】:
$arr = [
 [
  "16226281",
   "11",
   "Disclosure.1994.720p.BluRay.H264.AAC-RARBG",
   "finished"
],
[ 
  "16226038",
  "140",
  "Courage The Cowardly Dog (1999-2002)",
  "finished"
 ],
 [
  "16226020",
  "101",
  "[R.G. Mechanics] Call of Duty 4 Modern Warfare",
  "finished"
 ]
]


echo json_encode($arr);

点击以下链接:

http://php.net/manual/en/function.json-encode.php

【讨论】:

    【解决方案2】:

    只需创建一个数组

    <?php
       $arr = array(
           array(
             "16226281",
             "11",
             "Disclosure.1994.720p.BluRay.H264.AAC-RARBG",
             "finished"
           ),
           # ....
         );
    

    输出为 json

     <?php echo json_encode($arr);?>
    

    【讨论】:

      【解决方案3】:

      这是一个使用内置 json_encode PHP 函数的 JSON 编码示例,该函数可以从 PHP 数组创建 JSON 格式的数据:

      <?php
      $arr = array(
      'key 1' => "value 1",
      'key 2' => "value 2",
      'key 3' => "value 3"
      );
      echo json_encode($arr);
      ?>
      

      来源:How to create JSON formatted text in PHP

      【讨论】:

        猜你喜欢
        • 2018-05-08
        • 1970-01-01
        • 2010-11-26
        • 1970-01-01
        • 2015-05-29
        • 1970-01-01
        • 1970-01-01
        • 2021-12-01
        • 2015-11-22
        相关资源
        最近更新 更多