关联数组,json到php

时间:2013-02-06 10:29:46

标签: php json

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

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

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

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

相同
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\"}"} 

1 个答案:

答案 0 :(得分:1)

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

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

这是错误编码的数据,除非您想要JSON对象中的JSON对象。要使用它,您需要再次json_decode每个项目。但更好:修复编码步骤。