0

//编辑:这不是重复的,建议的线程对我没有帮助,因为我的问题与 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

4

1 回答 1

0

这可能是因为返回的 JSON 没有名为temp. 例如,我在 Fiddler 1http://api.openweathermap.org/data/2.5/history/city?id=2885679&type=hour&start=1369728000&end=1369789200&type=hour中尝试了以下 api 调用,但没有看到temp属性。

Json 被退回

于 2015-01-14T18:16:57.240 回答