I have a file called “config.json” which have
{
"book": {
"config": {
"uuid": "81393fe88f7c4e5a98070905790b39e1",
"type": "fullscreen",
"size": "1024,768"
}
}
}
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}"
then I want parse the data into json,but all the parse function couldn’t work,
var obj=$.parseJSON(data);
but the result is “null”
then I want use “jquery.json-2.3.js”
console.log(data.toJSON());
but the result is data.toJSON is not a function
How can I solve this problem?parse the string to json
jQuery automatically parses the response if you specify the dataType so calling
returns an error