[英]How to get deeper in the JSON body of a chainlink req.add(“path”) request? Add 2+ paths
I can get the results of the chainlink
path with req.add("path", "chainlink")
我可以使用
req.add("path", "chainlink")
chainlink
链环路径的结果
However, I want to return the price value, of "chainlink", "USD"
.但是,我想返回
"chainlink", "USD"
的价格值。 The output json has two paths, how do I reach the second path to get the price value? 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);
}
Here is the JSON response of the API这是 API 的 JSON 响应
{
chainlink: {
usd: 3.78
}
}
You can use the copy adapter with the copyPath
syntax.您可以使用带有
copyPath
语法的复制适配器。
string[] memory copyPath = new string[](2);
copyPath[0] = "chainlink";
copyPath[1] = "USD";
req.addStringArray("copyPath", copyPath);
Here is the whole function.这是整个 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.