//编辑:这不是重复的,建议的线程对我没有帮助,因为我的问题与 Newton.Json// 我将 Newtonsoft.Json 用于我的历史 Weatherapp(大学项目)。所以我选择使用 openweathermap.org。这是我的代码:
var request = (HttpWebRequest)WebRequest.Create("http://api.openweathermap.org/data/2.5/history/city?q=exampletown&start=1420135249&end=1421085649&type=hour")
var response = await request.GetResponseAsync();
var rawJson = new StreamReader(response.GetResponseStream()).ReadToEnd();
var json = JObject.Parse(rawJson);
string temp_value = json["temp"].ToObject<string>();
我总是遇到异常:NullReferenceException:对象引用未设置为对象的实例。附加信息:json 和 rawjson 不为 null,temp_value 为。当我在破旧的地方问这个问题时,我很抱歉。我是新来的人。
PS:uri 不完全正确,我将我的城镇替换为 exampletown