Blockchain 如何更深入地了解chainlink req.add(“path”)请求的JSON正文?增加2+;路径
我可以通过Blockchain 如何更深入地了解chainlink req.add(“path”)请求的JSON正文?增加2+;路径,blockchain,ethereum,solidity,Blockchain,Ethereum,Solidity,我可以通过req.add(“path”,“chainlink”) 但是,我想返回价格值,“chainlink”,“USD”。输出json有两条路径,如何到达第二条路径以获得价格值 function requestLINKPrice() public onlyOwner { Chainlink.Request memory req = buildChainlinkRequest(JOB, address(this), this.fulfill.selector);
req.add(“path”,“chainlink”)
但是,我想返回价格值,“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
}
}
您可以将与copyPath
语法一起使用
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);
}