我有一个来自MarkLogic的JSON响应,我绑定到C#中的模型。相关片段是以下:在.NET中绑定数组内的JSON对象
{
"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我修正了它,这只是返回的响应的一部分,这就是为什么当我复制它时无效 – OstrichGlue