我的 Javascript 有问题 -
$.ajax({
'url': message.action,
'data': parameterMap,
'cache': true,
'dataType': 'jsonp',
'jsonpCallback': 'cb',
'success': function(data, textStats, XMLHttpRequest) {
console.log(data);
var output = prettyPrint(data);
$("body").append(output);
}
});
这使用 PrettyPrint 输出 JSON。如何输出纯 json(没有 PrettyPrint)? 我试过了
$("body").append(data)
什么也没出现。
PS:我使用的是 YELP.com 提供的示例代码。这是整个代码的链接 - https://github.com/Yelp/yelp-api/blob/master/v2/js/search.html
最佳答案
对于支持 native JSON 编码/解码的现代浏览器,您可以使用
var output = JSON.stringify(data);
对于不支持的浏览器,您可以在 http://www.json.org/js.html 找到实现
关于javascript - 删除 PrettyPrint Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10627150/