0

在使用 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 的响应,但没有发现任何问题。想知道我是否遗漏了什么,或者产品 wiki 中的数据格式不正确?

4

1 回答 1

0

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

于 2013-01-04T02:33:26.620 回答