我有一个JSON从 API 返回数据的字符串流,如下所示:"{\"Recs\": [ {\"EID\":\"F67_24_6\",\"ReturnPeriod\":\"1\",\"GageStation\":\"NA\"}, {\"EID\":\"T67_24_6\",\"ReturnPeriod\":\"2.37\",\"GageStation\":\"Magueyes Island\"}, {\"EID\":\"R67_24_6\",\"ReturnPeriod\":\"1\",\"GageStation\":\"50147800\"}]}"我正在尝试反序列化它以返回:{"Recs":[ {"EID":"F67_24_6","ReturnPeriod":"1","GageStation":"NA"}, {"EID":"T67_24_6","ReturnPeriod":"2.37","GageStation":"Magueyes Island"}, {"EID":"R67_24_6","ReturnPeriod":"1","GageStation":"50147800"}]}我使用这些公共类来构建返回:public class New_Events_Dataset{ public string EID { get; set; } public string ReturnPeriod { get; set; } public string GageStation { get; set; }}public class NewRootObject{ public List<New_Events_Dataset> Reqs { get; set; }}当我稍后尝试应用此方法时,我基本上得到了{"Reqs":null}. 我在这里做错了什么?var jsonResponse = JsonConvert.DeserializeObject<NewRootObject>(strresult);string json = new JavaScriptSerializer().Serialize(jsonResponse);return json;
2 回答
繁花如伊
TA贡献2012条经验 获得超12个赞
我认为Reqs应该是Recs:
public class NewRootObject { public List<New_Events_Dataset> Reqs { get; set; } }
尝试:
public class NewRootObject { public List<New_Events_Dataset> Recs { get; set; } }
繁星点点滴滴
TA贡献1803条经验 获得超3个赞
将Reqs重命名为Recs并创建类的默认构造函数并实例化 Recs 列表
public class NewRootObject
{
List<New_Events_Dataset> Recs { get; set; }
public NewRootObject()
{
Recs = new List<New_Events_Dataset>();
}
}
- 2 回答
- 0 关注
- 99 浏览
添加回答
举报
0/150
提交
取消