Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中解析此JSON_Json - Fatal编程技术网

如何在PHP中解析此JSON

如何在PHP中解析此JSON,json,Json,我根据在我的网站上生成的表单构建这个JSON。 现在我想将单个项推送到数据库中,所以我需要能够通过迭代拉出指令 $instruction0 $instruction1 以及说明书中的成分 当试图解析JSON时,我得到一个错误,我不知道如何在PHP中读取它。(又名PHP NOOB)我能够通过Python获得我的所有项目所需的内容,没有任何问题 [ [ { "instruction": "Enter text here...asdada" }, {

我根据在我的网站上生成的表单构建这个JSON。 现在我想将单个项推送到数据库中,所以我需要能够通过迭代拉出指令

$instruction0 $instruction1

以及说明书中的成分

当试图解析JSON时,我得到一个错误,我不知道如何在PHP中读取它。(又名PHP NOOB)我能够通过Python获得我的所有项目所需的内容,没有任何问题

[
  [
    {
      "instruction": "Enter text here...asdada"
    },
    {
      "ingredient": "Beetroot",
      "amount": "2",
      "type": "grams"
    },
    {
      "ingredient": "Beetroot",
      "amount": "1",
      "type": "grams"
    }
  ],
  [
    {
      "instruction": "Enter text here..sdfsdf."
    },
    {
      "ingredient": "Carrot",
      "amount": "2",
      "type": "grams"
    },
    {
      "ingredient": "Beetroot",
      "amount": "525",
      "type": "grams"
    }
  ]
]

您是否尝试过使用第二个参数“true”指定您希望输出为关联数组

json_decode($json, true);
其次,如果您要手动将此json字符串发布到代码中,则需要将其包装在引号中,因此基于此

$json = '[ [ { "instruction": "Enter text here...asdada" }, { "ingredient": "Beetroot", "amount": "2", "type": "grams" }, { "ingredient": "Beetroot", "amount": "1", "type": "grams" } ], [ { "instruction": "Enter text here..sdfsdf." }, { "ingredient": "Carrot", "amount": "2", "type": "grams" }, { "ingredient": "Beetroot", "amount": "525", "type": "grams" } ] ] ';

$array = json_decode($json, true);

然后,您可以在
$array
中进行迭代,因为正常情况下

屏幕截图没有任何帮助。请粘贴您正在编写的实际代码,以及您看到的错误消息。