无法使用 JSON.Net 访问数组内的对象
public class VoskReturnArray
{
public string[] result { get; set; }
public string text { get; set; }
}
var voskArray = JsonSerializer.Deserialize<VoskReturnArray>(rec.Result());
Console.WriteLine(voskArray.text); // Works fine
Console.WriteLine(voskArray.result); // Throws an exception
尝试过<List<VoskReturnArray>>
,但随后text
不会出现。
我在这里缺少什么?
数据:
{
"result" : [{
"conf" : 0.228337,
"end" : 0.141508,
"start" : 0.060000,
"word" : "one"
}, {
"conf" : 1.000000,
"end" : 0.390000,
"start" : 0.141508,
"word" : "hundred"
}, {
"conf" : 1.000000,
"end" : 1.080000,
"start" : 0.390000,
"word" : "employees"
}],
"text" : "one hundred employees that's where it is you know they had the same problems are those five employees companies but they have the money to pay to fix them"
}
您的数据显示result
为对象数组,而模型中的result
属性VoskReturnArray
是字符串数组。它应该是这些对象的模型类型数组。所以而不是:
public string[] result { get; set; }
你会想要这样的:
public ResultItem[] result { get; set; }
...
public class ResultItem
{
public decimal conf { get; set; }
public decimal end { get; set; }
// etc
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句