Switched API from openweathermaps need some help ( using newtonsoft.json nuget ) c#

  • 1
  • Problem
  • Updated 3 years ago
  • (Edited)

Hello everyone,

My  previous code using openweather maps : http://hastebin.com/uzebomohon.vala

The problem im having right now is: 

 

I want to switch from openweathermap.org API to wunderground because it allows weather forecast by IP and is said to be more accurate. But seems a bit more complicated to convert and http://json2csharp.com/  isn't cutting it...

can someone please help me out?


Yes im using unity but I (think) I did everything needed for any weather API to work.

If I just know how to convert this to c sharp and properly log everything to console that should wrap my head around it enough to use it for whatever else so any help is greatly appreciated!

Photo of ㅇ새 ㅇ 국ㄸ긴

ㅇ새 ㅇ 국ㄸ긴

  • 12 Posts
  • 0 Reply Likes

Posted 3 years ago

  • 1
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
Even if having poor .NET skills hoping to be helpful.
You posted the class you're using with openweathermap, but what are the issues you're facing in writing the one to be binded to weatherunderground?
Generating this type of C# class looks pesky but not impossible.

By doing a quick search, an alternative method is available by using JObject.Parse from Newtonsoft.Json.Linq, traversing the JObject path and casting the wanted values as string 
see for more at 
http://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json_Linq_JObject_Parse.htm
http://www.newtonsoft.com/json/help/html/QueryJson.htm
Photo of ㅇ새 ㅇ 국ㄸ긴

ㅇ새 ㅇ 국ㄸ긴

  • 12 Posts
  • 0 Reply Likes
How accurate are Current Condition Phrases  exactly? I think I may have this figured out because parsing conditions is suddenly not a problem.
(Edited)
Photo of ㅇ새 ㅇ 국ㄸ긴

ㅇ새 ㅇ 국ㄸ긴

  • 12 Posts
  • 0 Reply Likes
So I got it to work exactly how I want it to now, grabbing the string output from the
conditions array and then creating an enum list containing all the condition phrases and then comparing them to the string output from the conditions array.

I get the current condition string output, it will go through my enum list, and if the current condition enum is equal to the current condition string output then : stuff happens!

However I hope the the API's condition information is accurate enough to know whether its truly currently raining outside or not... 
(Edited)
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
hi, seen a lot of improvements... well done

since I can mainly follow the programming aspects, I hope a Weather Underground representative can be clear about forecast "reliability index" to ensure the best success of your project.

about forecast response model, under simpleforecast you get today forecast and for next 3 days, but under txt_forecast it doubles since it returns splitted day and night forecasts, codeable via a for loop with index starting from 0; anyway if current conditions is needed, conditionsfeature may fit best http://www.wunderground.com/weather/api/d/docs?d=data/conditions
Photo of afelicioni

afelicioni

  • 227 Posts
  • 43 Reply Likes
hi, seen a lot of improvements... well done

since I can mainly follow the programming aspects, I hope a Weather Underground representative can be clear about forecast "reliability index" to ensure the best success of your project.

about forecast response model, under simpleforecast you get today forecast and for next 3 days, but under txt_forecast it doubles since it returns splitted day and night forecasts, codeable via a for loop with index starting from 0; anyway if current conditions is needed, conditionsfeature may fit best http://www.wunderground.com/weather/api/d/docs?d=data/conditions
Photo of ㅇ새 ㅇ 국ㄸ긴

ㅇ새 ㅇ 국ㄸ긴

  • 12 Posts
  • 0 Reply Likes
I thought i was already using the conditions feature?