[英]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.