【发布时间】:2016-10-23 09:08:53
【问题描述】:
我有一个来自 MarkLogic 的 JSON 响应,我将其绑定到 C# 中的模型。相关的sn-p如下:
{
"snippets":{
"match":[
{
"value":[
"In (consolidated) enforcement actions for failure to answer subpoena, appeal from ",
{
"highlight":{
"value":"judgement"
}
},
" for defendants."
]
}
]
}
}
我遇到的问题是外部“值”数组,因为它包含两个字符串和另一个 JSON 对象。有什么办法可以在 C# 中绑定这个数组?我当前的模型如下所示:
[JsonProperty(PropertyName = "snippets")]
public MarkLogicSnippetsModel Snippets { get; set; }
public class MarkLogicSnippetsModel
{
[JsonProperty(PropertyName = "match")]
public IEnumerable<MarkLogicMatchModel> Matches { get; set; }
}
public class MarkLogicMatchModel
{
[JsonProperty(PropertyName = "value")]
public IEnumerable<string> Values { get; set; }
}
但是当数组中有对象时,使用IEnumerable<string>就不起作用了。
【问题讨论】:
-
JSON 无效。
-
@PaulSwetz 我修复了它,这只是返回的响应的一部分,这就是为什么我复制它时它无效