如何解决C# JsonConvert 捕捉数据到对象错误
我想捕捉对象的响应数据
我想声明instant_price 默认使用instant_price_info 来捕获数组内部的数据,但是我尝试了错误我该怎么办
我想做这个怎么办
public class test
{
public test_info test_content { get; set; }
public test()
{
test_content = new test_info();
}
}
public class test_info
{
public string info1 { get; set; }
public string info2 { get; set; }
}
我创建了 Instant_price 类
public class instant_price
{
public Array msgArray { get; set; }
//public instant_price()
//{
// msgArray = new Array() { List<instant_price_info> };
//}
}
public class instant_price_info
{
public string c { get; set; }
public string n { get; set; }
public string d { get; set; }
public string t { get; set; }
public string o { get; set; }
public string h { get; set; }
public string l { get; set; }
public string z { get; set; }
public string tv { get; set; }
public string v{ get; set; }
public string a{ get; set; }
public string b { get; set; }
}
这个数据
{
"msgArray": [
{
"tv": "-","ps": "4","pz": "71.3000","fv": "1","oa": "71.1000","ob": "71.0000","c": "4126","d": "20210624","ch": "4126.tw","ot": "14:30:00","g": "7_12_27_15_53_","mt": "000000","ov": "1440","h": "71.3000","i": "22","it": "12","oz": "71.0000","l": "70.8000","t": "13:33:00","y": "70.8000","z": "71.3000","ts": "0"
}
],"userDelay": 5000,"rtmessage": "OK","cachedAlive": 737684
}
当我捕获响应数据时
instant_price stock = JsonConvert.DeserializeObject<instant_price>(responseResult);
我收到此错误代码
Newtonsoft.Json.JsonSerializationException: '无法创建 System.Array 类型的实例。类型是接口或抽象类,不能被实例化。路径 'msgArray',第 25 行,位置 13。'
解决方法
由于 JSon 结果是一个数组,您将需要使用 list
list>(responseResult);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。