我们对json的经验相当缺乏,并且在从Big Cartel商店到我们的WordPress网站的json字符串中显示对象时遇到了问题。
因此,如果在我们的Big Cartel网站上,我们会加载以下网址(这只是商店购物车位置的链接,最后是 .json ):
e.g。的 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网站中。
如果有人有任何想法,将不胜感激!谢谢!
答案 0 :(得分: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
答案 1 :(得分: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