C# 解析 Json - System.Runtime.Serialization.Json
我正在使用 System.Runtime.Serialization.Json 库
这不起作用
public class Detections
{
[DataContract]
public class RootObject
{
[DataMember(Name = "data")]
public DataObject Data { get; set; }
}
[DataContract]
public class DataObject
{
[DataMember(Name = "detections")]
public List<Detection> Detections { get; set; }
}
[DataContract]
public class Detection
{
[DataMember(Name = "language")]
public string Language { get; set; }
[DataMember(Name = "isReliable")]
public string IsReliable { get; set; }
[DataMember(Name = "confidence")]
public string Confidence { get; set; }
}
}
那么我应该如何解析它
{
"data": {
"detections": [
[
{
"language": "tr",
"isReliable": false,
"confidence": 0.086520955
}
]
]
}
}
I'm using the System.Runtime.Serialization.Json library
This doesn't Work
public class Detections
{
[DataContract]
public class RootObject
{
[DataMember(Name = "data")]
public DataObject Data { get; set; }
}
[DataContract]
public class DataObject
{
[DataMember(Name = "detections")]
public List<Detection> Detections { get; set; }
}
[DataContract]
public class Detection
{
[DataMember(Name = "language")]
public string Language { get; set; }
[DataMember(Name = "isReliable")]
public string IsReliable { get; set; }
[DataMember(Name = "confidence")]
public string Confidence { get; set; }
}
}
So how should I parse this
{
"data": {
"detections": [
[
{
"language": "tr",
"isReliable": false,
"confidence": 0.086520955
}
]
]
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
出现此问题的原因有两个。
1) 需要从Detections 类中删除您的嵌套类。
2) JSON 包含一个用于检测成员的多维数组,我认为它需要是单一的。
我已经测试了下面详细的代码,它工作正常。
我希望这对你有帮助。
The problem is occurring for two reasons.
1) Your nested classes needed to be removed from within the Detections class.
2) The JSON contains a multi-dimensional array for the detections member where I assume it needs to be single.
I have tested the code detailed below it works fine.
I Hope this helps you.
在你的 json 中,“Detection”是一个列表列表。请注意,jdavies 的答案不承认这一点。
In your json "Detection" is a list of lists. Please note that the answer from jdavies does not recognize this.
除了
Detections
是集合的集合之外,一切都是正确的。我不知道为什么会这样,但它对我有用。Everything is correct except that
Detections
is a collection of collections. I don't know why it is that way but it works for me.