将大卡特尔JSON对象加载到外部PHP

将大卡特尔JSON对象加载到外部PHP,json,wordpress,api,variables,bigcartel,Json,Wordpress,Api,Variables,Bigcartel,我们对json相当缺乏经验,并且在将一个json字符串中的对象从一个大型卡特尔商店显示到我们的WordPress站点时遇到了问题 因此,如果在我们的大型卡特尔网站上,我们加载以下URL(这只是指向商店购物车位置的链接,末尾带有.json): e、 g.ourstore.com/cart.json 我们得到以下变量字符串: {"items":[{"id":59269479,"name":"Test 4","price":"8.0","unit_price":"4.0","shipping":0.0

我们对json相当缺乏经验,并且在将一个json字符串中的对象从一个大型卡特尔商店显示到我们的WordPress站点时遇到了问题

因此,如果在我们的大型卡特尔网站上,我们加载以下URL(这只是指向商店购物车位置的链接,末尾带有.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\u count”:5变量显示到外部WordPress站点


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

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

不幸的是,您试图在外部Wordpress站点上使用的javascript API无法处理购物车数据——购物车信息只能直接显示在大型卡特尔商店中。有关这方面的更多信息,请参见:


不过,您可以使用我们的API在您的网站上显示其他商店和产品信息,更多详细信息和简短教程如下:

感谢您的回复,尽管如此,我尝试此功能时没有显示任何内容。“jsonObj.item_count”是否需要用其他格式包装?或者它还需要某种写入或打印功能吗?(此外,如果我们正在从动态url加载json,我们是否只需将上面的json变量替换为url?您能否提供代码,说明如何使用以下方法更改jsonI,该方法似乎有效:
var JSONObject={“items”:[],“item_count”:5,“price”:0,“total”:0};document.getElementById(“bagcount”).innerHTML=JSONObject.item_count;
但我们唯一需要的是动态加载JSONObject:您是否使用jQuery?我认为这将帮助您使用jQuery.getJSON(“,函数(数据){var jsonObj=JSON.parse(data);document.getElementById(“bagcount”).innerHTML=JSONObject.item_count});