-4

有人可以帮我用 jquery 接收这个 json 吗?

{
"output_type":"json","diagnostic":{"status":"200","elapsetime":"0.4187","memoryusage":"17.91MB","confirm":"success","lang":"id","currency":"IDR"},"results":{"result":[{"id":"business:3772","label":"Puri Maharani Boutique Hotel & Spa - Denpasar, Denpasar Timur, Kesiman Kertalangu","value":"Puri Maharani Boutique Hotel & Spa","category":"Hotel"},{"id":"business:3852","label":"Maharani Hotel  - Jakarta Selatan","value":"Maharani Hotel ","category":"Hotel"},{"id":"business:3874","label":"Maharadja Hotel - Jakarta Selatan, Mampang Prapatan, Tegal Parang","value":"Maharadja Hotel","category":"Hotel"},{"id":"business:4776","label":"Pita Maha Resort and Spa - Gianyar, Ubud, Ubud","value":"Pita Maha Resort and Spa","category":"Hotel"},{"id":"business:4779","label":"The Royal Pita Maha Resort and Spa - Gianyar, Ubud, Kedewatan","value":"The Royal Pita Maha Resort and Spa","category":"Hotel"},{"id":"business:18420","label":"Villa Mahapala Bali - Denpasar, Denpasar Selatan, Sanur","value":"Villa Mahapala Bali","category":"Hotel"},{"id":"business:105246","label":"Mahagiri Dreamland Villas & Spa - Badung, Kuta Selatan, Pecatu","value":"Mahagiri Dreamland Villas & Spa","category":"Hotel"}]},"token":"bc8d3a106572e4cff038261afb568ecf"}

我使用 $.getJSON 和 $.ajax 函数,但出现了一些问题,有人可以帮我处理一些 jquery 代码吗?

这是我的代码,

function getAPI() {
            jQuery.ajax({
            url: 'http://api.master18.tiket.com/search/autocomplete/hotel?q=mah&token=90d2fad44172390b11527557e6250e50&secretkey=83e2f0484edbd2ad6fc9888c1e30ea44&output=json',
        beforeSend: function(x) {
            if(x && x.overrideMimeType) {
             x.overrideMimeType("application/j-son;charset=UTF-8");
            }
        },
            type:"get",
            dataType: 'json',
            crossDomain: true,
         success: function(data) { console.log(data); }
         });
    }

但错误是 Uncaught SyntaxError: Unexpected token :

4

1 回答 1

2

您的问题似乎被标记为jsonp,所以我怀疑您正在尝试执行跨域 AJAX 调用。如果是这种情况,如果远程服务器支持,您确实可以使用JSONP 。

因此,如果您不进行跨域 AJAX 调用:

$.getJSON('/script', function(json) {
    // TODO: manipulate the result here
});

如果远程服务器支持 JSONP:

$.getJSON('http://example.com/script?callback?', function(json) {
    // TODO: manipulate the result here
});
于 2012-10-01T13:39:24.260 回答