Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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_编码值仅为';对象';_Php_Jquery_Json - Fatal编程技术网

PHP json_编码值仅为';对象';

PHP json_编码值仅为';对象';,php,jquery,json,Php,Jquery,Json,已解决-编辑:我最终不必使用php返回进行json解析或字符串化,因为我已经可以执行数据[I][“filesize”] 下面的代码只显示给我看 如果我将代码更改为dataType:text,那么它将输出在站点jsonformatter.curiousconcept.com上进行验证的代码。因此,对于datatype:text,我将尝试使用JSON.parse(result)手动解析它,这将使我在第一次粘贴中回到原始问题/输出。 我尝试过设置utf8编码的建议,在echo之前在php中设置head

已解决-编辑:我最终不必使用php返回进行json解析或字符串化,因为我已经可以执行数据[I][“filesize”]

下面的代码只显示给我看

如果我将代码更改为dataType:text,那么它将输出在站点jsonformatter.curiousconcept.com上进行验证的代码。因此,对于datatype:text,我将尝试使用JSON.parse(result)手动解析它,这将使我在第一次粘贴中回到原始问题/输出。 我尝试过设置utf8编码的建议,在echo之前在php中设置header,但仍然存在相同的问题。有什么帮助吗

    if(mysqli_num_rows($fres)){
        $row =  array();
        while ($frow = mysqli_fetch_assoc($fres)) {
            $row[] = array("path"=>myhtmlspecialchars($frow['path']),"filesize"=>mksize($frow['filesize']));            }
    echo json_encode($row);
///php的结尾

    $.ajax({
        type: 'POST',
        url: './getFilesList.php',
        data: {id : varId},
            dataType: 'JSON',
        cache: false,
        success: function(data){
        alert(data);
        }
    });

您是否尝试过
console.log(JSON.stringify(data))?如果不存在参数来告诉jquery响应是什么,它将尝试猜测并可以为您自动将json解析为对象。哇,json.stringify修复了这个问题。非常感谢。还有标题输入错误,意思是说“object”的字面值