Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中访问JSON中嵌套的数据?_Javascript_Arrays_Json_Google Apps Script_Google Sheets - Fatal编程技术网

如何在javascript中访问JSON中嵌套的数据?

如何在javascript中访问JSON中嵌套的数据?,javascript,arrays,json,google-apps-script,google-sheets,Javascript,Arrays,Json,Google Apps Script,Google Sheets,我几个小时来一直在想这个问题。我已经看到了,但我仍然无法理解这一点 我有一些Jason的数据,我知道是这样开始的: { "0x123454843eacf5c5318e1234504251b937d12345": [ { "poolIndex": 0, "stakingStrategy": "masterchef", "farmName": "sushiChef"

我几个小时来一直在想这个问题。我已经看到了,但我仍然无法理解这一点

我有一些Jason的数据,我知道是这样开始的:

{
  "0x123454843eacf5c5318e1234504251b937d12345": [
{
  "poolIndex": 0,
  "stakingStrategy": "masterchef",
  "farmName": "sushiChef",
 ....
我写了以下内容来获取“Poolidex”和“StackingStrategy”等信息:

这是行不通的。我已经用我能想到的每一种方法写了《第一次破解》

  theparsedJSONdata[walletAddress].poolIndex
  theparsedJSONdata[walletAddress][0].poolIndex
它们都不起作用。太令人沮丧了。任何帮助都将不胜感激

不管它值多少钱,`Object.keys(walletAddress)返回

下面是另一个函数:

  function pullAndParseAPISushi (walletAddress, networkName){

   console.log("walletAddress inside pullAndParseAPISushi is = " + walletAddress);
   console.log("network is " + networkName);
   var apiKEY = "96e0cc51-a62e-42ca-acee-910ea7d2a241";  // API key from Zapper
   var url = "https://api.zapper.fi/v1/staked-balance/masterchef?addresses%5B%5D="+ walletAddress + "&network=" + networkName + "&api_key=" + apiKEY;
   // assembles the API URL with the wallet addressa, network and name
   console.log("url is " + URL);
   var response = UrlFetchApp.fetch(url); // pulls data from the API
   console.log(response)
   var theparsedJSONdata = JSON.parse(response); // parses the JSON response from the API
   console.log(theparsedJSONdata)
   return theparsedJSONdata
 }
你试过了吗

theparsedJSONdata.walletAddress[0].poolIndex

没有足够的代表发表评论,但我认为这可能有效,让我知道

如果数据结构确实如您指定的那样,那么您尝试的其中一种尝试应该会起作用。参见下面的功能示例

const数据={
“0x123454843eacf5c5318e1234504251b937d12345”:[
{
“池索引”:0,
“战略”:“主厨”,
“农场名称”:“寿司厨师”,
}
]
}
const walletAddress=“0x123454843eacf5c5318e1234504251b937d12345”;
log(数据[walletAddress][0].Poolidex);

log(数据[walletAddress][0]谢谢!我还是不工作。我已经添加了这个
console.log(parsedJsonData[walletAddress][0].log)
和我得到以下错误:
TypeError:无法读取未定义的ParseTheDataFunctionsShi的属性“0”(walletAddress,networkName)
执行异步操作,如获取数据?我正在谷歌工作表中尝试从Zapper API中提取数据以跟踪交换中的位置。如果直接使用
console.log(ParsedJSONDATA)
可以得到什么?{0x123454843eacf5c531318e12345251b937d12345':[{poolIndex:0,LookStrategy:'masterchef',farmName:'sushiChef',rewardAddress:'0x0000000',tokenAddress:'0x000000',rewardTokenSymbol:'SUSHI',rewardTokenDecimals:18,rewardTokenAddress:'0x000000',rewardTokenPrice:12.12,isActive:true,标签:'WMATIC/ETH',协议:“SuxWeWAP”,考虑删除相关的问题。这是不可复制的。如果返回的JSON和代码与您所提到的完全一样,<代码> PARSEDJSONDATABOR[WALLATEDATA](0)。POOLLISTER < /代码>应该返回0。在调用<代码>之前,可以尝试记录<代码> PARSEDJSONDATABOS/COD> > PARSEDJSONDATA?[walletAddress][0]['Poolidex']
?您得到了什么?
  function pullAndParseAPISushi (walletAddress, networkName){

   console.log("walletAddress inside pullAndParseAPISushi is = " + walletAddress);
   console.log("network is " + networkName);
   var apiKEY = "96e0cc51-a62e-42ca-acee-910ea7d2a241";  // API key from Zapper
   var url = "https://api.zapper.fi/v1/staked-balance/masterchef?addresses%5B%5D="+ walletAddress + "&network=" + networkName + "&api_key=" + apiKEY;
   // assembles the API URL with the wallet addressa, network and name
   console.log("url is " + URL);
   var response = UrlFetchApp.fetch(url); // pulls data from the API
   console.log(response)
   var theparsedJSONdata = JSON.parse(response); // parses the JSON response from the API
   console.log(theparsedJSONdata)
   return theparsedJSONdata
 }
theparsedJSONdata.walletAddress[0].poolIndex