【发布时间】:2015-07-29 22:21:03
【问题描述】:
html
<input type="hidden" name="test[]" id="test" value= "" />
js
jQuery(document).on('click', '#target', function () {
var jsArr = ["val1", "val2", "val3"];
jQuery('input[name^="test[]"]').val(JSON.stringify(jsArr));
});
php
$json = $_POST['test'];
var_dump($json);
//array(1) { [0]=> string(43) "[\"val1\",\"val2\",\"val3\"]" }
var_dump($json[0]);
//string(43) "[\"val1\",\"val2\",\"val3\"]"
var_dump(json_decode($json[0]));
//return NULL
我的 json 字符串是有效的 json 格式,所以我不知道为什么它不起作用。任何的想法?
【问题讨论】:
-
echo json_last_error_msg();让我们看看 PHP 不喜欢什么。 -
var_dump(json_decode($json[0] , true));
-
或尝试:$json[0] = str_replace('\"' , '"' , $json[0]);可能是因为“逃逸”而发生这种情况
标签: javascript php json