Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP json_编码数组到javascript关联数组_Javascript_Php_Jquery - Fatal编程技术网

PHP json_编码数组到javascript关联数组

PHP json_编码数组到javascript关联数组,javascript,php,jquery,Javascript,Php,Jquery,我在mysqli中有一些专栏,我正在从PHP中阅读。它很吸引人,回声也很好 $results = mysqli_fetch_assoc(mysqli_query($conn, $querystring)); echo json_encode($results); //$results = {"title":"Sea Shells","location":"./Sea Shells.txt","type":"text"} 但是,javascript/jquery随后将回音作为字符串读取: va

我在mysqli中有一些专栏,我正在从PHP中阅读。它很吸引人,回声也很好

$results = mysqli_fetch_assoc(mysqli_query($conn, $querystring));
echo json_encode($results);

//$results = {"title":"Sea Shells","location":"./Sea Shells.txt","type":"text"}
但是,javascript/jquery随后将回音作为字符串读取:

var contentarr = [];
(ajax magic here, success: function(results){
    contentarr = results;
});
contentarr[0] = {
contentarr[1] = "
如何从PHP直接读取关联数组并将其映射到Javascript中的关联数组?Jquery是我使用的唯一库。

Change contentarr=结果; 到 contentarr=JSON.parseresults


这将转换为javascipt对象。

在JavaScript中,php的json|de|en]代码的等价物是json.stringify和json.parse-如果使用jQuery的ajax方法,应该已经得到一个json.parsed对象作为结果-如果设置了正确的内容头“content-Type:application/json”;在php中,这真是一件幸事