0

Sorry, total noob here, working on an arduino project.

It ends up getting a weather service, however, the example code i have only gets the weather, i'd like to get the temperature too.

So instead of making 2 requests, i'd like to return an object, and parse it from there.

So, how do i make an object like:

{"weather":"Sunny","temperature":"22"}

from this:

void onSuccess(HttpResponse & response)
{
  /* Using the response to query the Json chain till the required value. */
  /* i.e. Get the value of 'main' in the first object of the array 'weather' in the response. */
  /* Providing that the response is in JSON format. */
  response["weather"][0]["main"].query();
}

Edit: Definition of HTTP class:

HttpRequest request("http://api.openweathermap.org/data/2.5/weather?q=skopje");
R0b0tn1k
  • 4,256
  • 14
  • 46
  • 64
  • 1
    Is the response in this format already? Or is it in a different format, but you only need to extract temperature and weather out of it? – SingerOfTheFall Aug 26 '15 at 13:09
  • 1
    Please provide the defeinition of HttpResponse class – jpo38 Aug 26 '15 at 13:11
  • Is this a .NET `HttpResponse`, or something else? – Carlton Aug 26 '15 at 13:17
  • Why not use a Json parser/generator? – Sorin Aug 26 '15 at 14:10
  • @SingerOfTheFall You're right, turns out it already has that data in there – R0b0tn1k Aug 27 '15 at 08:49
  • @jpo38 Added definition – R0b0tn1k Aug 27 '15 at 08:49
  • @Carlton I've no idea, it's from here: https://codebender.cc/sketch:144438 – R0b0tn1k Aug 27 '15 at 08:50
  • @Sorin I would if i knew how :) – R0b0tn1k Aug 27 '15 at 08:50
  • I'm assuming this is a Java `HttpResponse`, in which case [this thread](http://stackoverflow.com/questions/18073849/get-json-object-from-a-http-response) has some useful info on how to get a JSON object from an HttpResonse. I would first dump the contents of the JSON object to a text file, then browse through it manually to see how the temperature data is stored. Retrieving that data in your program should be analogous to getting the weather data. – Carlton Aug 27 '15 at 11:37

0 Answers0