0

在我的 php 文件中,我使用以下内容,

$obj = ($_POST['data']);
var_dump(json_decode($obj,true));

我看到了这个结果。这是正确的格式吗?以及如何访问数组。

例如,设置一个与 row1 id 相同的新变量 $newID

array(4) {
  ["row0"]=>
  string(92) "{"id":"157","name":"123","basic":"123123123","submitter":"Keith","status":"review"}"
  ["row1"]=>
  string(169) "{"id":"158","name":"TEST RESOURCE","basic":"Please state the type of work.","submitter":"Keith","status":"review"}"
  ["row2"]=>
  string(107) "{"id":"159","name":"TEST OTHER","basic":"testing for other","submitter":"Keith","status":"review"}"
  ["row3"]=>
  string(160) "{"id":"160","name":"Name","basic":"type of work","submitter":"Keith","status":"review"}"
}

这是萤火虫中的 POST 内容

data    {"row0":"{\"id\":\"157\",\"name\":\"123\",\"basic\":\"123123123\",\"submitter\":\"Keith\",\"status\":\"review\"}","row1":"{\"id\":\"158\",\"name\":\"TEST RESOURCE\",\"basic\":\"Please state the type of work.\",\"submitter\":\"Keith\",\"status\":\"review\"}","row2":"{\"id\":\"159\",\"name\":\"TEST OTHER\",\"basic\":\"testing for other\",\"submitter\":\"Keith\",\"status\":\"review\"}","row3":"{\"id\":\"160\",\"name\":\"Name\",\"basic\":\"type of work\",\"submitter\":\"Keith\",\"status\":\"review\"}"} 
4

1 回答 1

1

数组的每一“行”都是另一个 JSON 字符串。数据似乎是双重编码的,例如:

$array = json_encode(
    array(
        'row0' => json_encode(array('id' => '157', ...)),
        ...
    )
)

这是错误编码的数据,除非您希望 JSON 对象包含在 JSON 对象中。要使用它,您需要json_decode再次处理每个单独的项目。更好的是:修复编码步骤。

于 2013-02-06T10:33:58.013 回答