jquery $ .ajax函数返回的数据无法解析为json [英] The data which jquery $.ajax function return could not be parse to json

查看:127
本文介绍了jquery $ .ajax函数返回的数据无法解析为json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为config.json的文件,其中

I have a file called "config.json" which have

{
    "book": {
        "config": {
            "uuid": "81393fe88f7c4e5a98070905790b39e1",
            "type": "fullscreen",
            "size": "1024,768"
                  }
             }
}

然后我使用$ .ajax来读取此文件,

then I use $.ajax to read this file,

    $.ajax({
        url:...,
        data:{...},
        type:"get",
        dataType:'json',
        success:function(data, textStatus){
            console.log(data);
        }
    })

但数据返回的字符串格式如下:

but the data return is string format like:

"{\n "book": {\n ... }\n }\n }\n}"

然后我想将数据解析为json,但所有解析函数都无法正常工作,

then I want parse the data into json,but all the parse function couldn't work,

var obj=$.parseJSON(data);

但结果为null

然后我想使用jquery.json-2.3.js

then I want use "jquery.json-2.3.js"

console.log(data.toJSON());

但结果是 data.toJSON不是函数

如何解决这个问题?将字符串解析为json

How can I solve this problem?parse the string to json

推荐答案

如果指定dataType,jQuery会自动解析响应,因此调用

jQuery automatically parses the response if you specify the dataType so calling

var obj=$.parseJSON(data);

返回错误

这篇关于jquery $ .ajax函数返回的数据无法解析为json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆