blockchain - 如何更深入地了解 chainlink req.add("path") 请求的 JSON 正文?添加 2+ 路径
问题描述
我可以得到chainlink
路径的结果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);
}
推荐阅读
- html - bootstrap 4.1 移动菜单按钮不起作用
- c++ - std::vector erase() 没有按预期工作
- java - 如何使用 Java Optional 优雅地替换三元运算符
- azure-devops - Azure DevOps 分支策略路径筛选器,用于检测项目根文件夹中的更改
- java - 如何为tomcat webapps配置设置正确的windows路径
- java - Gradle:无法创建 SecurityManager
- html - Rowspan 属性不适用于倒排表
- perforce - 如何 p4 在不同的客户端取消搁置但保持相同的搁置 CL?
- java - java泛型多类边界
- r - 如何有效地强制多个数据框共享的列属于同一类类型