我们对json相当缺乏经验,并且很难将json字符串中的对象从一个大卡特尔商店显示到我们的WordPress站点。
因此,如果在我们的大卡特尔网站上,我们加载了以下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站点中。
如果任何人有任何想法,将是非常感谢!谢谢!
发布于 2014-04-15 17:14:59
不幸的是,您试图在外部Wordpress站点上使用的javascript无法处理购物车数据--购物车信息只能直接显示在大型卡特尔商店中。有关这方面的更多信息,请参见:http://help.bigcartel.com/customer/portal/articles/772751-javascript-ajax
您可以使用我们的API在您的网站上显示其他商店和产品信息,更详细的信息和一个简短的教程在这里:http://help.bigcartel.com/customer/portal/articles/772771-api。
发布于 2014-04-15 09:36:00
请在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
https://stackoverflow.com/questions/23079598
复制相似问题