在PHP中获取第二级JSON数据

在PHP中获取第二级JSON数据,php,arrays,json,Php,Arrays,Json,我有遵循此模型的JSON数据: { "questions": [ { "questionKey": 0, "question": "string", "required": true, "type": "multipleChoice", "maxSize": 0, "answers": [ { "answer": "string", "answerKey":

我有遵循此模型的JSON数据:

{
  "questions": [
    {
      "questionKey": 0,
      "question": "string",
      "required": true,
      "type": "multipleChoice",
      "maxSize": 0,
      "answers": [
        {
          "answer": "string",
          "answerKey": 0
        }
      ]
    }
  ],
  "fields": [
    {
      "field": "string",
      "answers": [
        "string"
      ],
      "required": true,
      "maxSize": 0
    }
  ]
}
我很难获得所有字段>字段值。当我进行var_转储($jsondata)时,它会打印所有数据,这样我就知道我正在获取和存储数据。我知道我需要做一个foreach语句,比如:

foreach ($jsondata as $data) { 
echo $data['fields'];
}

我知道这是错误的,但我不知道如何循环遍历所有字段>字段值。非常感谢您的帮助:)

尝试以下方法:

//Decode JSON string into a PHP array.
$jsonData = json_decode($jsonStr, true);

//Loop through it like any associative array.
foreach($jsonData['fields'] as $field){
    var_dump($field);
    echo $field['field'] , '<br>';
}
//将JSON字符串解码到PHP数组中。
$jsonData=json_decode($jsonStr,true);
//像任何关联数组一样循环它。
foreach($jsonData['fields']作为$field){
变量转储($field);
echo$field['field'],“
”; }
太棒了,非常感谢你,韦恩,这真是一种享受。我试着在一辆车里做一辆车,但那不是我的方法。你所做的完全有道理。干杯