- Posts: 25
- Thank you received: 5
var client = new System.Net.WebClient();
var jsonString = client.DownloadString("apiurl");
dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString);
var qpf = double.Parse(result .forecast.simpleforecast.forecastday[0].qpf_allday.mm.Value);
Please Log in or Create an account to join the conversation.
private System.Reflection.MethodInfo _deserializeObjectMethodInfo;
public System.Reflection.MethodInfo DeserializeObjectMethodInfo
{
get
{
if (_deserializeObjectMethodInfo == null)
{
var assembly = System.Reflection.Assembly.LoadFrom("Newtonsoft.Json.dll");
var jobjectType = assembly.GetType("Newtonsoft.Json.JsonConvert");
_deserializeObjectMethodInfo = jobjectType.GetMethods().SingleOrDefault(m => m.Name == "DeserializeObject" && !m.IsGenericMethod && m.ReturnType==typeof(object) && m.GetParameters().Count()==1);
//can also use Parse method from JObject
//var jobjectType = assembly.GetType("Newtonsoft.Json.Linq.JObject");
//_deserializeObjectMethodInfo= jobjectType.GetMethod("Parse");
}
return _deserializeObjectMethodInfo;
}
}
dynamic dynObj = DeserializeObjectMethodInfo.Invoke(this, new object[] { jsonString });
Please Log in or Create an account to join the conversation.