简体   繁体   English

关联数组,将json转换为php

[英]associative array, json to php

In my php file im using the following, 在我的php文件中,使用以下命令,

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

And i see this result. 我看到了这个结果。 Is this the correct format? 这是正确的格式吗? and how do i access the array. 以及如何访问数组。

eg, set a new variable $newID the same as row1 id 例如,将新变量$ 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"}"
}

heres whats in POST in firebug 继承人在萤火虫中的开机自检

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

Each "row" of the array is another JSON string. 数组的每个“行”都是另一个JSON字符串。 It seems like the data was double-encoded, like: 数据似乎经过了双重编码,例如:

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

This is incorrectly encoded data, unless you wanted JSON objects inside JSON objects. 除非您要在JSON对象中使用JSON对象,否则这是编码错误的数据。 To work with it, you need to json_decode each individual item again. 要使用它,您需要再次对每个单独的项目进行json_decode Better though: fix the encoding step. 更好的是:修复编码步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM