繁体   English   中英

如何深入了解链链接 req.add(“path”) 请求的 JSON 主体? 添加 2+ 路径

[英]How to get deeper in the JSON body of a chainlink req.add(“path”) request? Add 2+ paths

我可以使用req.add("path", "chainlink") chainlink链环路径的结果

但是,我想返回"chainlink", "USD"的价格值。 output json有两条路径,如何到达第二条路径获取价格值?

  function requestLINKPrice() 
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(JOB, address(this), this.fulfill.selector);
    req.add("get", "https://api.coingecko.com/api/v3/simple/price?ids=chainlink&vs_currencies=usd");
    req.add("path", "chainlinkUSD");
    req.addInt("times", 100);
    sendChainlinkRequestTo(ORACLE, req, ORACLE_PAYMENT);
  }

这是 API 的 JSON 响应

{
  chainlink: {
    usd: 3.78
  }
}

您可以使用带有copyPath语法的复制适配器

string[] memory copyPath = new string[](2);
copyPath[0] = "chainlink";
copyPath[1] = "USD";
req.addStringArray("copyPath", copyPath);

这是整个 function。

  function requestLINKPrice() 
    public
    onlyOwner
  {
    Chainlink.Request memory req = buildChainlinkRequest(JOB, address(this), this.fulfill.selector);
    req.add("get", "https://api.coingecko.com/api/v3/simple/price?ids=chainlink&vs_currencies=usd");
    string[] memory copyPath = new string[](2);
    copyPath[0] = "chainlink";
    copyPath[1] = "USD";
    req.addStringArray("copyPath", copyPath);
    req.addInt("times", 100);
    sendChainlinkRequestTo(ORACLE, req, ORACLE_PAYMENT);
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM