如何在Php中创建Json

时间:2017-01-09 10:25:27

标签: php json

如何在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"
  ]
]

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

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

只需创建一个数组

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

和输出为json

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

答案 2 :(得分:0)

以下是使用内置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