我有一个json结果,我试图循环,但它似乎退出我的foreach,这是我的json结果
{
"word": "example",
"results": [{
"definition": "a representative form or pattern",
"partOfSpeech": "noun",
"synonyms": ["model"],
"typeOf": ["representation", "internal representation", "mental representation"],
"hasTypes": ["prefiguration", "archetype", "epitome", "guide", "holotype", "image", "loadstar", "lodestar", "microcosm", "original", "paradigm", "pilot", "prototype", "template", "templet", "type specimen"],
"derivation": ["exemplify"],
"examples": ["I profited from his example"]
}, {
"definition": "something to be imitated",
"partOfSpeech": "noun",
"synonyms": ["exemplar", "good example", "model"],
"typeOf": ["ideal"],
"hasTypes": ["pacemaker", "pattern", "beauty", "prodigy", "beaut", "pacesetter"],
"derivation": ["exemplify", "exemplary"]
}, {
"definition": "an occurrence of something",
"partOfSpeech": "noun",
"synonyms": ["case", "instance"],
"typeOf": ["happening", "natural event", "occurrence", "occurrent"],
"hasTypes": ["clip", "mortification", "piece", "time", "humiliation", "bit"],
"derivation": ["exemplify"],
"examples": ["but there is always the famous example of the Smiths"]
}, {
"definition": "an item of information that is typical of a class or group",
"partOfSpeech": "noun",
"synonyms": ["illustration", "instance", "representative"],
"typeOf": ["information"],
"hasTypes": ["excuse", "apology", "specimen", "case in point", "sample", "exception", "quintessence", "precedent"],
"derivation": ["exemplify", "exemplary"],
"examples": ["this patient provides a typical example of the syndrome", "there is an example on page 10"]
}, {
"definition": "punishment intended as a warning to others",
"partOfSpeech": "noun",
"synonyms": ["deterrent example", "lesson", "object lesson"],
"typeOf": ["monition", "admonition", "word of advice", "warning"],
"derivation": ["exemplary"],
"examples": ["they decided to make an example of him"]
}, {
"definition": "a task performed or problem solved in order to develop skill or understanding",
"partOfSpeech": "noun",
"synonyms": ["exercise"],
"typeOf": ["lesson"],
"examples": ["you must work the examples at the end of each chapter in the textbook"]
}],
"syllables": {
"count": 3,
"list": ["ex", "am", "ple"]
},
"pronunciation": {
"all": "ɪɡ'zæmpəl"
},
"frequency": 4.67
}
我的代码如下,将json字符串输入到动态变量中,以循环显示结果(至少我正在尝试
dynamic words = JObject.Parse(responseString);
if (words.results != null)
{
try
{
foreach (dynamic example in words.results)
{
MessageBox.Show("result");
if (example.partOfSpeech != null)
{
builder.AppendText("Type");
builder.AppendBreak(new TimeSpan(10000000));
builder.AppendText(example.partOfSpeech);
builder.AppendBreak(new TimeSpan(10000000));
}
MessageBox.Show("result");
if (example.definition != null)
{
builder.AppendText("Definition");
builder.AppendBreak(new TimeSpan(10000000));
builder.AppendText(example.definition);
builder.AppendBreak(new TimeSpan(10000000));
}
MessageBox.Show("result");
if (example.examples != null)
{
builder.AppendText("Example sentence");
builder.AppendBreak(new TimeSpan(10000000));
builder.AppendText(example.examples[0]);
}
MessageBox.Show("result");
}
}
}
我很想循环遍历每个结果,但它似乎没有用我的代码来做,怎么可以
我循环结果?