开发者

All instances of a node by xxxx name

Is there a one liner or how can I get all instances of a named list in any node?

say I get jason where multiple nodes could have a sub collection called "comments". How can I get all nodes that contain a colle开发者_Go百科ction of "comments"?

Thanks,


If you can provide an example of the JSON, I can give you a definitive answer.

However, I can post some of the JSON I'm parsing and you can see how it works and possibly shape it to fit your needs.

"abridged_cast": [
    {
        "name": "Clark Gable",
        "characters": ["Rhett Butler"]
    },
    {
        "name": "Vivien Leigh",
        "characters": ["Scarlett O'Hara"]
    },
    {
        "name": "Leslie Howard",
        "characters": ["Ashley Wilkes"]
    },
    {
        "name": "Olivia de Havilland",
        "characters": ["Melanie Hamilton"]
    },
    {
        "name": "Hattie McDaniel",
        "characters": ["Mammy"]
    }
],

Notice how abridged_cast is an array of values, and one value in that array (characters) is an array itself.

Here's how I fetch the data:

var castMembers = (JArray) x["abridged_cast"];
foreach (var castMember in castMembers)
{
    CastMember member = new CastMember();
    member.Actor = (string) castMember["name"];
    var characters = (JArray) castMember["characters"];
    foreach (var character in characters)
    {
        member.Characters.Add((string)character);
        movie.Cast.Add(member);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜