getJSON中的jQuery解析错误

时间:2012-12-30 22:57:26

标签: jquery getjson

在使用ProductWiki API搜索产品时,我遇到了JSON解析错误。如果我遗漏了某些内容或者返回的数据格式不正确,你能告诉我吗?

以下是我正在使用的JavaScript代码

var searchUrl = "http://api.productwiki.com/connect/api.aspx?" +
            "&op=search" +
            "&key=" + API_KEY_PRODUCT_WIKI +
            "&q=" + nugget +
            "&format=json" +
            "&jsoncallback=?";

 $.getJSON(searchUrl, function (data) { alert("Got data"); });

在执行代码时,我从productwiki

获取以下数据
{"__type":"ProductWiki.DataStructures.API.Schema.pw_api_results, ProductWiki.DataStructures, Version=1.0.4622.22636, Culture=neutral, PublicKeyToken=null","message":null,"num_results":2,"products":[{"__type":"ProductWiki.DataStructures.API.Schema.product, ProductWiki.DataStructures, Version=1.0.4622.22636, Culture=neutral, PublicKeyToken=null","url":"http://www.productwiki.com/microsoft-surface/","id":15113,"title":"Microsoft Surface","description":null,"proscore":"41","number_of_reviews":"13","category":"Computers","key_features":[],"images":[{"__type":"ProductWiki.DataStructures.API.Schema.image, ProductWiki.DataStructures, Version=1.0.4622.22636, Culture=neutral, PublicKeyToken=null","title":"Microsoft Surface","rawimage":"http://images.productwiki.com/upload/images/microsoft_surface.jpg","largeimage":"http://images.productwiki.com/upload/images/microsoft_surface-400-400.jpg","mediumimage":"http://images.productwiki.com/upload/images/microsoft_surface-100-100.jpg","smallimage":"http://images.productwiki.com/upload/images/microsoft_surface-60-60.jpg"}],"community_review":null,"reviews":null,"tags":null,"competitors":null,"related":null,"skus":null},{"__type":"ProductWiki.DataStructures.API.Schema.product, ProductWiki.DataStructures, Version=1.0.4622.22636, Culture=neutral, PublicKeyToken=null","url":"http://www.productwiki.com/menotek-flexible-bluetooth-waterproof-mini-keyboard/","id":59084,"title":"Menotek Flexible Bluetooth Waterproof Mini Keyboard","description":null,"proscore":"62","number_of_reviews":"1","category":"Keyboards","key_features":[],"images":[{"__type":"ProductWiki.DataStructures.API.Schema.image, ProductWiki.DataStructures, Version=1.0.4622.22636, Culture=neutral, PublicKeyToken=null","title":"Menotek Flexible Bluetooth Waterproof Mini Keyboard","rawimage":"http://images.productwiki.com/upload/images/menotek_flexible_bluetooth_waterproof_mini_keyboard.jpg","largeimage":"http://images.productwiki.com/upload/images/menotek_flexible_bluetooth_waterproof_mini_keyboard-400-400.jpg","mediumimage":"http://images.productwiki.com/upload/images/menotek_flexible_bluetooth_waterproof_mini_keyboard-100-100.jpg","smallimage":"http://images.productwiki.com/upload/images/menotek_flexible_bluetooth_waterproof_mini_keyboard-60-60.jpg"}],"community_review":null,"reviews":null,"tags":null,"competitors":null,"related":null,"skus":null}]}

但它也会抛出jquery错误

JavaScript critical error at line 1, column 10 in http://api.productwiki.com/connect/api.aspx?&op=search&key=***&q=microsoftsurface&format=json&jsoncallback=jQuery18308245886188083906_1356907329390&_=1356907329577

SCRIPT1004: Expected ';'

我尝试在JSON Formatter & validator验证来自productwiki的回复,但没有发现任何问题。想知道我是否遗漏了某些东西,或者产品维基的数据是不是格式正确吗?

1 个答案:

答案 0 :(得分:0)

我认为productwiki不支持jsonp。我最终从服务器端访问了他们的API