0

I have this JSON format:

string jsonFormat = @"{ 
""Applications"": {
        ""data"": {
            ""Application named one"": [
                {
                    ""index"" : ""1"",
                    ""name"" : ""One"",
                    ""active"" : ""1"",
                    ""excluded"" : ""false""
                }
            ],
            ""Application named two"": [
                {
                    ""index"" : ""2"",
                    ""forum"" : ""yes"",
                }
            ]
        } 
    } 
}"; 

How exactly I can acces data childrens ? I need to retreive Application named one and Application named two - for each also the attributes with their values - the attributes are different from Application to Application.

Untill now I have:

        JObject resultt= JObject.Parse(jsonFormat);
        // get JSON result objects into a list
        IList<JToken> results = resultt["Applications"]["data"].Children().ToList();

I looked over JSON.net documentation and could not find a solution for this...

Any help will be very usefull. Thank you.

1
  • I just can not getting work ... Commented Aug 23, 2011 at 19:43

1 Answer 1

1

I think you are looking for something like this:

JObject jObject = JObject.Parse(jsonFormat);
int index = jObject
    .Value<JObject>("Applications")
    .Value<JObject>("data")
    .Value<JArray>("Application named one")
    .First
    .Value<int>("index");

Basically the idea is to use the Value method with the type you are expecting to retrieve a specific json element (JObject, JArray, ...) or parse a .NET value (int, string, bool, ...).

Sign up to request clarification or add additional context in comments.

1 Comment

isn't exactly what I wanted - and I'm saying this because I do not know "Application named one" name but I figured out a solution for this. I'll post the solution tomorrow or the day after tomorrow. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.