wordpress 将Big Cartel JSON对象加载到外部PHP

cidc1ykv  于 5个月前  发布在  WordPress
关注(0)|答案(2)|浏览(67)

我们对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,"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站点。
如果任何人有任何想法,将不胜感激!

laximzn5

laximzn51#

不幸的是,您尝试在外部WordPress站点上使用的JavaScript API无法处理购物车数据--购物车信息只能直接显示在Big Cartel商店中。
您可以使用我们的API在您的网站上显示其他商店和产品信息,更多详细信息和简短的教程在这里:http://help.bigcartel.com/customer/portal/articles/772771-api

fgw7neuy

fgw7neuy2#

请在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

相关问题