1

Is it possible to get multiple values in single Oraclize query?

contract CheckBet is usingOraclize {

struct Weather {
    uint curr_temperature;
    uint high_temperature;
    uint low_temperature;
}
Weather weather;

/// Event for debugging
event Log(string text);

function CheckBet() {
    get_weather_status();
}

function get_weather_status() payable{
    Log("Oraclize query was sent, waiting for the answer.."); 
    (oraclize_query("URL","json(http://samples.openweathermap.org/data/2.5/weather?q=Lond`on,uk&appid=b6907d289e10d714a6e88b30761fae22).main.temp_min"));
}

//callback function for Oraclize
function __callback(bytes32 _myid, string _result) {
    require (msg.sender == oraclize_cbAddress());
    Log(_result);
    weather.low_temperature = parseInt(_result); 
}

In function get_weather_status, I'm getting min. temp. I want temp_max, curr_temp too.

Is it possible in single Oraclize query?

JSON FILE

{
  "main": {
   "temp":280.32,
   "pressure":1012,
   "humidity":81,
   "temp_min":279.15,
   "temp_max":281.15
  }
}
1

Quick googling says it might not be trivial. Have a look at https://github.com/oraclize/ethereum-examples/issues/10 So, you'd have to parse the result yourself.

P.S. Please accept the answers to your previous questions if you are satisfied with them.

1

You should be able do this using JSONPATH.

(oraclize_query("URL","json(http://samples.openweathermap.org/data/2.5/weather?q=Lond`on,uk&appid=b6907d289e10d714a6e88b30761fae22).main[temp, temp_min, temp_max]"));

You can examine the results here http://app.oraclize.it/home/test_query#VVJMKEdFVCk=:anNvbihodHRwOi8vc2FtcGxlcy5vcGVud2VhdGhlcm1hcC5vcmcvZGF0YS8yLjUvd2VhdGhlcj9xPUxvbmRgb24sdWsmYXBwaWQ9YjY5MDdkMjg5ZTEwZDcxNGE2ZTg4YjMwNzYxZmFlMjIpLm1haW5bdGVtcCwgdGVtcF9taW4sIHRlbXBfbWF4XQ==

0

For the query: "json(http://samples.openweathermap.org/data/2.5/weather?q=Lond`on,uk&appid=b6907d289e10d714a6e88b30761fae22).main[temp, pressure, humidity, temp_min, temp_max]"

Follow these rules: https://github.com/json-path/JsonPath

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.