我可以从一个 URL 中获取两个变量吗

问题描述

`pragma solidity ^0.4.22;
import "github.com/provable-things/ethereum-api/provableAPI_0.4.25.sol";

contract ExampleContract is usingProvable {

   string public ETHUSD;
   event LogConstructorInitiated(string nextStep);
   event LogPriceUpdated(string price);
   event LogNewProvableQuery(string description);

   function ExampleContract() payable {
       LogConstructorInitiated("Constructor was initiated. Call 'updatePrice()' to send the Provable Query.");
   }

   function __callback(bytes32 myid,string result) {
       if (msg.sender != provable_cbAddress()) revert();
       ETHUSD = result;
       LogPriceUpdated(result);
   }

   function updatePrice() payable {
       if (provable_getPrice("URL") > this.balance) {
           LogNewProvableQuery("Provable query was NOT sent,please add some ETH to cover for the query fee");
       } else {
           LogNewProvableQuery("Provable query was sent,standing by for the answer..");
            provable_query("URL","json(https://api.pro.coinbase.com/products/ETH-USD/ticker).price");
       }
   }`

这是代码,我的问题是:

代码的最后一行,我有一个 provable_query,它包含 URL 和 URL 数据是 [{"Trade_id":103437884,"price":"2674.1","size":"0.12890079","time": "2021-04-28T11:19:29.475452Z","bid":"2673.78","ask":"2674.03","volume":"360649.21208837"} 所以最后我想将价格提取到区块链中。

"但我的问题是,如果此 URL 包含 2 个不同的价格,例如 1 个美元价格和其他欧元价格,例如:{"Trade_id":103437884,"price1":"2674.1","price2": "2222",size":"0.12890079","time":"2021-04-28T11:19:29.475452Z","volume":"360648.237"}

所以现在我的问题是如何从上述 URL 中获取价格 1 和价格 2,如果是,我如何从单个 URL 中获取 2 个价格”。

提前致谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)