如何深入 JSON chainlink req.add("path") 请求的主体?添加 2+ 路径

How to get deeper in the JSON body of a chainlink req.add("path") request? Add 2+ paths

我可以用 req.add("path", "chainlink")

得到 chainlink 路径的结果

不过,我想要return的价格值,"chainlink", "USD"。输出 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
  }
}

您可以将 copy adaptercopyPath 语法一起使用。

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

这是整个函数。

  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);
  }