【发布时间】:2013-09-03 21:20:21
【问题描述】:
我从服务中返回了以下 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()));
}
}
【问题讨论】: