Parsing history not working

  • 1
  • Question
  • Updated 6 years ago
How can I extract temperature from a history json? I tried using the following command:
var temp_f = parsed_json['history']['dailysummary']['meantempi[0]'];
and it comes back saying undefined. It seems like there is a problem in extracting array type data. If anyone has a solution, please respond.
Photo of Minonk

Minonk

  • 2 Posts
  • 0 Reply Likes

Posted 6 years ago

  • 1
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
Just trying to guess it


var temp_f = parsed_json['history']['dailysummary'][0]['meantempi'];


but revealing more details about used language or application could help in finding a right/better solution.

[edit]
please copy the above code as a single line
Photo of Minonk

Minonk

  • 2 Posts
  • 0 Reply Likes
Thanks for the suggestion. It worked. I knew I had to put a [0] somewhere but couldn't find documentation on json to determine where. I tried [dailysummary[0] ] and that didn't work. I just needed more info on how to use json parsing. I am using it in javascript and it is working great now. Thanks again.
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
you're welcome
happy coding
Photo of radonneus

radonneus

  • 3 Posts
  • 0 Reply Likes
Hi all, great weather API, absolutely great.

Now about history, I use the API to get history_YYYYMMDD using coordinates in my query.
I really don't mind getting only a few records of the specified day in history, for example: 07:00 AM, 08:30 AM and 03:00 PM.
But in some cases I get too many results, and it happens that I get 2 results for the same hour:minutte and they are not the same. Are they coming from different weather stations ?
Example: 00:00 AM,00:30 AM,01:00 AM,01:00 AM,01:30 AM,02:00 AM, etc. We have two 01:00 AM's.
What result should I use for the same day/hour/minutte between those 2 ?

Yes, the difference between them is minor, a few degrees regarding conditions ... fine ... but please explain. It's a little bit confusing.
Now, in my code (php), I check for duplicates and only fetch one, the first one between this two duplicates.
I'll copy/paste an API call example if requested, demonstratind my dilema.

Thank you very much Wunderground Team, best regards !
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
Since I'm fresh to this community, I don't know if there is a previous or official answer, but I can think of history response as an aggregated archive from multiple sources if you query for a geographic position.

As a suggestion, if I were you and I could decode METAR data, I would look at the "metar" field of each "observation" piece; from what I have realized, this represents an econded message about the data source, so same time structure should have different METAR message.
Photo of radonneus

radonneus

  • 3 Posts
  • 0 Reply Likes
Ok, I've studied METAR data format and yes, indeed, in my case I receive history conditions from 2 different weather stations. So the API returns this aggregate archive, fine, no problem, my bad for not documenting myself about METAR. This is new to me.

I'll keep my code as it is now, meaning I'll build a compilation between all weather stations in order to have al least hourly info.

Anyway, for people who want to understand METAR data format and information included, check: http://en.wikipedia.org/wiki/METAR

Thank you for your reply afelicioni. All the best to you.