我有以下代码:
$_REQUEST[ 'LOM' ]
var_dump($_REQUEST[ 'LOM' ]);
结果是以下JSON:
{
"id":0,
"type":"root",
"related_dropzone_id":0,
"related_dropzone_order":0,
"children":{
"1376071054231":{
"id":"1376071054231",
"type":"section",
"related_dropzone_id":0,
"related_dropzone_order":1,
"dropzones":{
"A":1376071054231
},
"options":{
},
"children":{
"1376071056267":{
"id":"1376071056267",
"type":"section",
"related_dropzone_id":1376071054231,
"related_dropzone_order":0,
"dropzones":{
"A":1376071056267
},
"options":{
}
}
}
}
}
}
但在使用“正确”的以下代码时:
$result = json_decode($_REQUEST[ 'LOM' ]);
var_dump($result); // the result is NULL
为什么它不将JSON转换为数组?
我测试了这种方式,但没有工作:
$result = json_decode( "'" . $_REQUEST[ 'LOM' ] . "'");
var_dump($result); // the result is NULL
答案 0 :(得分:2)
<?php
$so=$_REQUEST[ 'LOM' ];
json_decode( $so, true, 9 )
$json_errors = array(
JSON_ERROR_NONE => 'No error has occurred',
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
JSON_ERROR_SYNTAX => 'Syntax error',
);
echo 'Last error : ', $json_errors[json_last_error()], PHP_EOL, PHP_EOL;
首先尝试使用此代码,如果您采用语法错误可能会对您有所帮助;
$so = str_replace('"', '"', $_REQUEST[ 'LOM' ]);
答案 1 :(得分:0)
感谢@merdincz。
我用以下代码解决了:
var_dump( json_decode( str_replace( '\\', '', $_REQUEST[ 'LOM' ] ) );