0

我们对 json 相当缺乏经验,并且无法将来自 Big Cartel 商店的 json 字符串中的对象显示到我们的 WordPress 网站。

因此,如果在我们的 Big Cartel 网站上,我们会加载以下 URL(这只是指向商店购物车位置的链接,末尾带有.json):

例如ourstore.com/cart.json

我们得到以下变量字符串:

{"items":[{"id":59269479,"name":"Test 4","price":"8.0","unit_price":"4.0","shipping":0.0,"tax":0.0,"total":"4.0","quantity":2,"product":"test-4","option":59269479},{"id":59269434,"name":"Test 2","price":"2.0","unit_price":"1.0","shipping":0.0,"tax":0.0,"total":"1.0","quantity":2,"product":"test-2","option":59269434},{"id":59271363,"name":"Test 6","price":"544.0","unit_price":"544.0","shipping":0.0,"tax":0.0,"total":"544.0","quantity":1,"product":"test-6","option":59271363}],"item_count":5,"price":"554.0","total":"554.0"}

从该字符串中,我们基本上只是试图将“item_count”:5变量显示到外部 WordPress 站点。

如果有人有任何想法,将不胜感激!谢谢!

4

2 回答 2

0

请在 javascript 中使用此代码。

var jsonString = '{"items":[{"id":59269479,"name":"Test 4","price":"8.0","unit_price":"4.0","shipping":0.0,"tax":0.0,"total":"4.0","quantity":2,"product":"test-4","option":59269479},{"id":59269434,"name":"Test 2","price":"2.0","unit_price":"1.0","shipping":0.0,"tax":0.0,"total":"1.0","quantity":2,"product":"test-2","option":59269434},{"id":59271363,"name":"Test 6","price":"544.0","unit_price":"544.0","shipping":0.0,"tax":0.0,"total":"544.0","quantity":1,"product":"test-6","option":59271363}],"item_count":5,"price":"554.0","total":"554.0"}';
var jsonObj = JSON.parse(jsonString);

现在只需在要显示的地方使用以下行

jsonObj.item_count
于 2014-04-15T09:36:00.233 回答
0

不幸的是,您尝试在外部 Wordpress 网站上使用的 javascript API 无法处理购物车数据——购物车信息只能直接显示在 Big Cartel 商店中。更多信息在这里:http ://help.bigcartel.com/customer/portal/articles/772751-javascript-ajax

您可以使用我们的 API 在您的网站上显示其他商店和产品信息,更多详细信息和简要教程在这里:http ://help.bigcartel.com/customer/portal/articles/772771-api

于 2014-04-15T17:14:59.480 回答