简体   繁体   English

jQuery / JSON:无法获取JSON?

[英]JQuery/JSON: Can't get JSON?

Why can't I get this JSON when it's properly formatted? 正确格式化后,为什么无法获取此JSON?

jQuery.getJSON("http://sandbox.buscape.com/service/findProductList/564771466d477a4458664d3d/?keyword=drive&format=json", function(result){

        alert('ok');

    });

Because it comes from a different domain. 因为它来自不同的域。 You have to use JSONP, luckily the API you are using supports it (by setting the callback parameter): 您必须使用JSONP,幸运的是,您使用的API支持它(通过设置callback参数):

$.ajax({
    dataType : 'jsonp',
    url : 'http://sandbox.buscape.com/service/findProductList/564771466d477a4458664d3d/?keyword=drive&format=json&callback=?',
    success : function(data) {
        console.log(data);
    }
});

Almost certainly the accented characters in the file are causing problems. 几乎可以肯定,文件中的重音字符会引起问题。 For instance, í shows up in "Sistema Operacional Compatível" . 例如,í显示在"Sistema Operacional Compatível" If the encoding is not correct, it will be seen as an invalid UTF-8 character. 如果编码不正确,它将被视为无效的UTF-8字符。 Make sure that the encoding is correct, or manually encode to UTF-8. 确保编码正确,或手动编码为UTF-8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM