开发者

Deserialize JSON using JSON.net in Wp7 application

开发者 https://www.devze.com 2023-03-29 18:13 出处:网络
I have this JSON format: string jsonFormat = @\"{ \"\"Applications\"\": { \"\"data\"\": { \"\"Application named one\"\": [

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.


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, ...).

0

精彩评论

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