我从服务返回了以下 json:
{
responseHeader: {
status: 0,
QTime: 1
},
spellcheck: {
suggestions: [
"at",
{
numFound: 2,
startOffset: 0,
endOffset: 2,
suggestion: [
"at least five tons of glitter alone had gone into it before them and",
"at them the designer of the gun had clearly not been instructed to beat"
]
},
"collation",
"(at least five tons of glitter alone had gone into it before them and)"
]
}
}
- 我需要在 c# 中创建“建议”元素内的内容列表。什么是最好的方法?
- 没有被“”包围的元素是什么。不应该所有的json元素都被“”包围吗?谢谢。
编辑:这是基于 dcastro 的回答
dynamic resultChildren = result.spellcheck.suggestions.Children();
foreach (dynamic child in resultChildren)
{
var suggestionObj = child as JObject;
if (suggestionObj != null)
{
var subArr = suggestionObj.Value<JArray>("suggestion");
strings.AddRange(subArr.Select(suggestion => suggestion.ToString()));
}
}