0
Controller
{
namespace WebApplication10.Controllers
{
public class Default1Controller : ApiController
{
[ResponseType(typeof(WeatherItem))]
public WeatherItem Post(Wcall call)
{
string apikey = //MYAPIKEY;
string url = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&units=metric&cnt=1&APPID={1}", call.city1, apikey);
WebClient A1 = new WebClient();
string dataweather = A1.DownloadString(url);
WeatherItem a2 = JsonConvert.DeserializeObject<WeatherItem>(dataweather);
string przyklad = a2.list.pressure;
return a2;
}
}
}
}
class
{
namespace WebApplication10.Models
{
public class WeatherItem
{
public List list { get; set; }
public string cod { get; set; }
public string message { get; set; }
public int cnt { get; set; }
//public List<City> city { get; set; }
}
public class List
{
public int dt { get; set; }
// public List<Temp> temp { get; set; }
public string pressure { get; set; }
public int humidity { get; set; }
// public List<Weather> weather { get; set; }
public string speed { get; set; }
public string deg { get; set; }
public string clauds { get; set; }
public int rain { get; set; }
}
public class Wcall
{
public string city1 { get; set; }
public string street { get; set; }
}
public class City
{
public int id { get; set; }
public string name { get; set; }
//public List<Coords> coords { get; set; }
public string country { get; set; }
public int population { get; set; }
}
public class Coords
{
public string lon { get; set; }
public string lat { get; set; }
}
public class Temp
{
public string day { get; set; }
public string min { get; set; }
public string max { get; set; }
public string night { get; set; }
public string eve { get; set; }
public string morn { get; set; }
}
public class Weather
{
public int id { get; set; }
public string main { get; set; }
public string description { get; set; }
public string icon { get; set; }
}
}
}
异常:类型的异常 “Newtonsoft.Json.JsonSerializationException”发生在 Newtonsoft.Json.dll但在用户代码附加 信息没有处理:不能反序列化当前JSON对象(例如 {“name”:“value”})...Json的反序列化错误C#MVC
对不起,我有一个想法,我做错了什么?
将您返回的值加回到'dataweather' ... –