C# get value from deserialized json object





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







3















I'm currently Deserializing a json string using the Newtonsoft.Json nuget packet using the following code:



var data = (JObject)JsonConvert.DeserializeObject(json);


Now I'm receiving an object in the following format:



{{  "meta": {    "rap": 2098,    "count": 5  },  "data": [    {      "name": "Gold Tetramino of Mastery",      "rap": 735,      "uaid": "16601901",      "link": "https://www.roblox.com/Gold-Tetramino-of-Mastery-item?id=5786047",      "img": "https://t4.rbxcdn.com/081337d7ea86e6a406512aaa83bbcdeb",      "serial": "---",      "count": 1    },    {      "name": "Silver Tetramino of Accomplishment",      "rap": 385,      "uaid": "16601900",      "link": "https://www.roblox.com/Silver-Tetramino-of-Accomplishment-item?id=5786026",      "img": "https://t1.rbxcdn.com/60da69cd76f8dad979326f63f4a5b657",      "serial": "---",      "count": 1    },    {      "name": "Subzero Ski Specs",      "rap": 370,      "uaid": "155175547",      "link": "https://www.roblox.com/Subzero-Ski-Specs-item?id=19644587",      "img": "https://t4.rbxcdn.com/8ead2b0418ef418c7650d34103d39b6d",      "serial": "---",      "count": 1    },    {      "name": "Rusty Tetramino of Competence",      "rap": 319,      "uaid": "16601899",      "link": "https://www.roblox.com/Rusty-Tetramino-of-Competence-item?id=5785985",      "img": "https://t2.rbxcdn.com/968ad11ee2f4ee0861ae511c419148c8",      "serial": "---",      "count": 1    },    {      "name": "Bluesteel Egg of Genius",      "rap": 289,      "uaid": "16601902",      "link": "https://www.roblox.com/Bluesteel-Egg-of-Genius-item?id=1533893",      "img": "https://t7.rbxcdn.com/48bf59fe531dd1ff155e455367e52e73",      "serial": "---",      "count": 1    }  ]}}


Now I'm trying to get the following value from it:



"rap": 2098,


I just need 2098 and I've been trying the following code:



string rap = data["rap"].Value<string>();


But sadly this wouldn't work. Does anyone have a idea how to get the value?










share|improve this question

























  • Parse it instead of deserializing if you only need one value

    – Make StackOverflow Good Again
    Jan 19 '17 at 22:33


















3















I'm currently Deserializing a json string using the Newtonsoft.Json nuget packet using the following code:



var data = (JObject)JsonConvert.DeserializeObject(json);


Now I'm receiving an object in the following format:



{{  "meta": {    "rap": 2098,    "count": 5  },  "data": [    {      "name": "Gold Tetramino of Mastery",      "rap": 735,      "uaid": "16601901",      "link": "https://www.roblox.com/Gold-Tetramino-of-Mastery-item?id=5786047",      "img": "https://t4.rbxcdn.com/081337d7ea86e6a406512aaa83bbcdeb",      "serial": "---",      "count": 1    },    {      "name": "Silver Tetramino of Accomplishment",      "rap": 385,      "uaid": "16601900",      "link": "https://www.roblox.com/Silver-Tetramino-of-Accomplishment-item?id=5786026",      "img": "https://t1.rbxcdn.com/60da69cd76f8dad979326f63f4a5b657",      "serial": "---",      "count": 1    },    {      "name": "Subzero Ski Specs",      "rap": 370,      "uaid": "155175547",      "link": "https://www.roblox.com/Subzero-Ski-Specs-item?id=19644587",      "img": "https://t4.rbxcdn.com/8ead2b0418ef418c7650d34103d39b6d",      "serial": "---",      "count": 1    },    {      "name": "Rusty Tetramino of Competence",      "rap": 319,      "uaid": "16601899",      "link": "https://www.roblox.com/Rusty-Tetramino-of-Competence-item?id=5785985",      "img": "https://t2.rbxcdn.com/968ad11ee2f4ee0861ae511c419148c8",      "serial": "---",      "count": 1    },    {      "name": "Bluesteel Egg of Genius",      "rap": 289,      "uaid": "16601902",      "link": "https://www.roblox.com/Bluesteel-Egg-of-Genius-item?id=1533893",      "img": "https://t7.rbxcdn.com/48bf59fe531dd1ff155e455367e52e73",      "serial": "---",      "count": 1    }  ]}}


Now I'm trying to get the following value from it:



"rap": 2098,


I just need 2098 and I've been trying the following code:



string rap = data["rap"].Value<string>();


But sadly this wouldn't work. Does anyone have a idea how to get the value?










share|improve this question

























  • Parse it instead of deserializing if you only need one value

    – Make StackOverflow Good Again
    Jan 19 '17 at 22:33














3












3








3








I'm currently Deserializing a json string using the Newtonsoft.Json nuget packet using the following code:



var data = (JObject)JsonConvert.DeserializeObject(json);


Now I'm receiving an object in the following format:



{{  "meta": {    "rap": 2098,    "count": 5  },  "data": [    {      "name": "Gold Tetramino of Mastery",      "rap": 735,      "uaid": "16601901",      "link": "https://www.roblox.com/Gold-Tetramino-of-Mastery-item?id=5786047",      "img": "https://t4.rbxcdn.com/081337d7ea86e6a406512aaa83bbcdeb",      "serial": "---",      "count": 1    },    {      "name": "Silver Tetramino of Accomplishment",      "rap": 385,      "uaid": "16601900",      "link": "https://www.roblox.com/Silver-Tetramino-of-Accomplishment-item?id=5786026",      "img": "https://t1.rbxcdn.com/60da69cd76f8dad979326f63f4a5b657",      "serial": "---",      "count": 1    },    {      "name": "Subzero Ski Specs",      "rap": 370,      "uaid": "155175547",      "link": "https://www.roblox.com/Subzero-Ski-Specs-item?id=19644587",      "img": "https://t4.rbxcdn.com/8ead2b0418ef418c7650d34103d39b6d",      "serial": "---",      "count": 1    },    {      "name": "Rusty Tetramino of Competence",      "rap": 319,      "uaid": "16601899",      "link": "https://www.roblox.com/Rusty-Tetramino-of-Competence-item?id=5785985",      "img": "https://t2.rbxcdn.com/968ad11ee2f4ee0861ae511c419148c8",      "serial": "---",      "count": 1    },    {      "name": "Bluesteel Egg of Genius",      "rap": 289,      "uaid": "16601902",      "link": "https://www.roblox.com/Bluesteel-Egg-of-Genius-item?id=1533893",      "img": "https://t7.rbxcdn.com/48bf59fe531dd1ff155e455367e52e73",      "serial": "---",      "count": 1    }  ]}}


Now I'm trying to get the following value from it:



"rap": 2098,


I just need 2098 and I've been trying the following code:



string rap = data["rap"].Value<string>();


But sadly this wouldn't work. Does anyone have a idea how to get the value?










share|improve this question
















I'm currently Deserializing a json string using the Newtonsoft.Json nuget packet using the following code:



var data = (JObject)JsonConvert.DeserializeObject(json);


Now I'm receiving an object in the following format:



{{  "meta": {    "rap": 2098,    "count": 5  },  "data": [    {      "name": "Gold Tetramino of Mastery",      "rap": 735,      "uaid": "16601901",      "link": "https://www.roblox.com/Gold-Tetramino-of-Mastery-item?id=5786047",      "img": "https://t4.rbxcdn.com/081337d7ea86e6a406512aaa83bbcdeb",      "serial": "---",      "count": 1    },    {      "name": "Silver Tetramino of Accomplishment",      "rap": 385,      "uaid": "16601900",      "link": "https://www.roblox.com/Silver-Tetramino-of-Accomplishment-item?id=5786026",      "img": "https://t1.rbxcdn.com/60da69cd76f8dad979326f63f4a5b657",      "serial": "---",      "count": 1    },    {      "name": "Subzero Ski Specs",      "rap": 370,      "uaid": "155175547",      "link": "https://www.roblox.com/Subzero-Ski-Specs-item?id=19644587",      "img": "https://t4.rbxcdn.com/8ead2b0418ef418c7650d34103d39b6d",      "serial": "---",      "count": 1    },    {      "name": "Rusty Tetramino of Competence",      "rap": 319,      "uaid": "16601899",      "link": "https://www.roblox.com/Rusty-Tetramino-of-Competence-item?id=5785985",      "img": "https://t2.rbxcdn.com/968ad11ee2f4ee0861ae511c419148c8",      "serial": "---",      "count": 1    },    {      "name": "Bluesteel Egg of Genius",      "rap": 289,      "uaid": "16601902",      "link": "https://www.roblox.com/Bluesteel-Egg-of-Genius-item?id=1533893",      "img": "https://t7.rbxcdn.com/48bf59fe531dd1ff155e455367e52e73",      "serial": "---",      "count": 1    }  ]}}


Now I'm trying to get the following value from it:



"rap": 2098,


I just need 2098 and I've been trying the following code:



string rap = data["rap"].Value<string>();


But sadly this wouldn't work. Does anyone have a idea how to get the value?







c# json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 20 '17 at 0:06









Peter Ritchie

30.1k97192




30.1k97192










asked Jan 19 '17 at 22:31









d4ned4ne

1612




1612













  • Parse it instead of deserializing if you only need one value

    – Make StackOverflow Good Again
    Jan 19 '17 at 22:33



















  • Parse it instead of deserializing if you only need one value

    – Make StackOverflow Good Again
    Jan 19 '17 at 22:33

















Parse it instead of deserializing if you only need one value

– Make StackOverflow Good Again
Jan 19 '17 at 22:33





Parse it instead of deserializing if you only need one value

– Make StackOverflow Good Again
Jan 19 '17 at 22:33












8 Answers
8






active

oldest

votes


















4














Try:



var result = data["meta"]["rap"].Value<int>();


or



var result = data.SelectToken("meta.rap").ToString();


or if you don't want to want to pass the whole path in, you could just search for the property like this:



var result = data.Descendants()
.OfType<JProperty>()
.FirstOrDefault(x => x.Name == "rap")
?.Value;





share|improve this answer

































    2














    Instead of declaring as type var and letting the compiler sort it, declare as a dynamic and using the Parse method.



    dynamic data = JArray.Parse(json);


    Then try



    data.meta.rap


    To get the internal rap object.
    I edited from using the deserializeobject method as i incorrectly thought that had the dynamic return type. See here on json.net documentation for more details: http://www.newtonsoft.com/json/help/html/QueryJsonDynamic.htm






    share|improve this answer


























    • There is no Parse method on JsonConvert.

      – William
      Jan 19 '17 at 23:08











    • @billisphere thanks, should have triple checked..!

      – Chris Watts
      Jan 20 '17 at 6:18






    • 1





      As suggested by stackoverflow.com/questions/47134936/…, I'm using dynamic data = JObject.Parse(json);, which seems to work without exceptions.

      – Jari Turkia
      Nov 20 '18 at 9:40



















    1














    var jobject = (JObject)JsonConvert.DeserializeObject(json);
    var jvalue = (JValue)jobject["meta"]["rap"];
    Console.WriteLine(jvalue.Value); // 2098





    share|improve this answer































      0














      The value is actually an int type. Try:



      int rap = data["rap"].Value<int>();





      share|improve this answer































        0














        string rap = JsonConvert.DeserializeObject<dynamic>(json).meta.rap;
        Console.WriteLine(rap); // 2098


        If you're not into dynamic (or aren't using .NET 4+), I like how this other answer relies solely on Json.NET's API.






        share|improve this answer

































          0














          Just use dynamic representation of object:



          dynamic obj = JsonConvert.DeserializeObject(json)
          var value = obj.meta.rap;


          JObject easily convertable to dynamic type itself. You can either get string or int from this value:



          var ivalue = (int)obj.meta.rap;
          var svalue = (string)obj.meta.rap;





          share|improve this answer

































            0














            Try to use as following



            var test = JsonConvert.DeserializeObject<dynamic>(param);

            var testDTO = new TPRDTO();
            testDTO.TPR_ID = test.TPR_ID.Value;


            Note: For using of JsonConvert class you have to install Newton-Soft from your package-manager






            share|improve this answer

































              0














              the problem is that you are casting the deserialized json into a JObject. if you want to have the JObject then simple do this:



              JObject.Parse(json); 


              then you have the JObject and you can access a specific path (for extracting value see this )



              you have also another option which is to deserialize your json into a class that you have in your code like this:



              var instanceOFTheClass =  JsonConvert.DeserializeObject<YourClassName>(json); 


              with the above code you can access any property and values you want.






              share|improve this answer
























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41752928%2fc-sharp-get-value-from-deserialized-json-object%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                8 Answers
                8






                active

                oldest

                votes








                8 Answers
                8






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                4














                Try:



                var result = data["meta"]["rap"].Value<int>();


                or



                var result = data.SelectToken("meta.rap").ToString();


                or if you don't want to want to pass the whole path in, you could just search for the property like this:



                var result = data.Descendants()
                .OfType<JProperty>()
                .FirstOrDefault(x => x.Name == "rap")
                ?.Value;





                share|improve this answer






























                  4














                  Try:



                  var result = data["meta"]["rap"].Value<int>();


                  or



                  var result = data.SelectToken("meta.rap").ToString();


                  or if you don't want to want to pass the whole path in, you could just search for the property like this:



                  var result = data.Descendants()
                  .OfType<JProperty>()
                  .FirstOrDefault(x => x.Name == "rap")
                  ?.Value;





                  share|improve this answer




























                    4












                    4








                    4







                    Try:



                    var result = data["meta"]["rap"].Value<int>();


                    or



                    var result = data.SelectToken("meta.rap").ToString();


                    or if you don't want to want to pass the whole path in, you could just search for the property like this:



                    var result = data.Descendants()
                    .OfType<JProperty>()
                    .FirstOrDefault(x => x.Name == "rap")
                    ?.Value;





                    share|improve this answer















                    Try:



                    var result = data["meta"]["rap"].Value<int>();


                    or



                    var result = data.SelectToken("meta.rap").ToString();


                    or if you don't want to want to pass the whole path in, you could just search for the property like this:



                    var result = data.Descendants()
                    .OfType<JProperty>()
                    .FirstOrDefault(x => x.Name == "rap")
                    ?.Value;






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jan 19 '17 at 23:12

























                    answered Jan 19 '17 at 22:35









                    StuartStuart

                    2,6711016




                    2,6711016

























                        2














                        Instead of declaring as type var and letting the compiler sort it, declare as a dynamic and using the Parse method.



                        dynamic data = JArray.Parse(json);


                        Then try



                        data.meta.rap


                        To get the internal rap object.
                        I edited from using the deserializeobject method as i incorrectly thought that had the dynamic return type. See here on json.net documentation for more details: http://www.newtonsoft.com/json/help/html/QueryJsonDynamic.htm






                        share|improve this answer


























                        • There is no Parse method on JsonConvert.

                          – William
                          Jan 19 '17 at 23:08











                        • @billisphere thanks, should have triple checked..!

                          – Chris Watts
                          Jan 20 '17 at 6:18






                        • 1





                          As suggested by stackoverflow.com/questions/47134936/…, I'm using dynamic data = JObject.Parse(json);, which seems to work without exceptions.

                          – Jari Turkia
                          Nov 20 '18 at 9:40
















                        2














                        Instead of declaring as type var and letting the compiler sort it, declare as a dynamic and using the Parse method.



                        dynamic data = JArray.Parse(json);


                        Then try



                        data.meta.rap


                        To get the internal rap object.
                        I edited from using the deserializeobject method as i incorrectly thought that had the dynamic return type. See here on json.net documentation for more details: http://www.newtonsoft.com/json/help/html/QueryJsonDynamic.htm






                        share|improve this answer


























                        • There is no Parse method on JsonConvert.

                          – William
                          Jan 19 '17 at 23:08











                        • @billisphere thanks, should have triple checked..!

                          – Chris Watts
                          Jan 20 '17 at 6:18






                        • 1





                          As suggested by stackoverflow.com/questions/47134936/…, I'm using dynamic data = JObject.Parse(json);, which seems to work without exceptions.

                          – Jari Turkia
                          Nov 20 '18 at 9:40














                        2












                        2








                        2







                        Instead of declaring as type var and letting the compiler sort it, declare as a dynamic and using the Parse method.



                        dynamic data = JArray.Parse(json);


                        Then try



                        data.meta.rap


                        To get the internal rap object.
                        I edited from using the deserializeobject method as i incorrectly thought that had the dynamic return type. See here on json.net documentation for more details: http://www.newtonsoft.com/json/help/html/QueryJsonDynamic.htm






                        share|improve this answer















                        Instead of declaring as type var and letting the compiler sort it, declare as a dynamic and using the Parse method.



                        dynamic data = JArray.Parse(json);


                        Then try



                        data.meta.rap


                        To get the internal rap object.
                        I edited from using the deserializeobject method as i incorrectly thought that had the dynamic return type. See here on json.net documentation for more details: http://www.newtonsoft.com/json/help/html/QueryJsonDynamic.htm







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jan 20 '17 at 6:19

























                        answered Jan 19 '17 at 22:39









                        Chris WattsChris Watts

                        3151218




                        3151218













                        • There is no Parse method on JsonConvert.

                          – William
                          Jan 19 '17 at 23:08











                        • @billisphere thanks, should have triple checked..!

                          – Chris Watts
                          Jan 20 '17 at 6:18






                        • 1





                          As suggested by stackoverflow.com/questions/47134936/…, I'm using dynamic data = JObject.Parse(json);, which seems to work without exceptions.

                          – Jari Turkia
                          Nov 20 '18 at 9:40



















                        • There is no Parse method on JsonConvert.

                          – William
                          Jan 19 '17 at 23:08











                        • @billisphere thanks, should have triple checked..!

                          – Chris Watts
                          Jan 20 '17 at 6:18






                        • 1





                          As suggested by stackoverflow.com/questions/47134936/…, I'm using dynamic data = JObject.Parse(json);, which seems to work without exceptions.

                          – Jari Turkia
                          Nov 20 '18 at 9:40

















                        There is no Parse method on JsonConvert.

                        – William
                        Jan 19 '17 at 23:08





                        There is no Parse method on JsonConvert.

                        – William
                        Jan 19 '17 at 23:08













                        @billisphere thanks, should have triple checked..!

                        – Chris Watts
                        Jan 20 '17 at 6:18





                        @billisphere thanks, should have triple checked..!

                        – Chris Watts
                        Jan 20 '17 at 6:18




                        1




                        1





                        As suggested by stackoverflow.com/questions/47134936/…, I'm using dynamic data = JObject.Parse(json);, which seems to work without exceptions.

                        – Jari Turkia
                        Nov 20 '18 at 9:40





                        As suggested by stackoverflow.com/questions/47134936/…, I'm using dynamic data = JObject.Parse(json);, which seems to work without exceptions.

                        – Jari Turkia
                        Nov 20 '18 at 9:40











                        1














                        var jobject = (JObject)JsonConvert.DeserializeObject(json);
                        var jvalue = (JValue)jobject["meta"]["rap"];
                        Console.WriteLine(jvalue.Value); // 2098





                        share|improve this answer




























                          1














                          var jobject = (JObject)JsonConvert.DeserializeObject(json);
                          var jvalue = (JValue)jobject["meta"]["rap"];
                          Console.WriteLine(jvalue.Value); // 2098





                          share|improve this answer


























                            1












                            1








                            1







                            var jobject = (JObject)JsonConvert.DeserializeObject(json);
                            var jvalue = (JValue)jobject["meta"]["rap"];
                            Console.WriteLine(jvalue.Value); // 2098





                            share|improve this answer













                            var jobject = (JObject)JsonConvert.DeserializeObject(json);
                            var jvalue = (JValue)jobject["meta"]["rap"];
                            Console.WriteLine(jvalue.Value); // 2098






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 19 '17 at 22:46









                            EricEric

                            1,1321915




                            1,1321915























                                0














                                The value is actually an int type. Try:



                                int rap = data["rap"].Value<int>();





                                share|improve this answer




























                                  0














                                  The value is actually an int type. Try:



                                  int rap = data["rap"].Value<int>();





                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    The value is actually an int type. Try:



                                    int rap = data["rap"].Value<int>();





                                    share|improve this answer













                                    The value is actually an int type. Try:



                                    int rap = data["rap"].Value<int>();






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jan 19 '17 at 22:46









                                    simonlchildssimonlchilds

                                    2,47011222




                                    2,47011222























                                        0














                                        string rap = JsonConvert.DeserializeObject<dynamic>(json).meta.rap;
                                        Console.WriteLine(rap); // 2098


                                        If you're not into dynamic (or aren't using .NET 4+), I like how this other answer relies solely on Json.NET's API.






                                        share|improve this answer






























                                          0














                                          string rap = JsonConvert.DeserializeObject<dynamic>(json).meta.rap;
                                          Console.WriteLine(rap); // 2098


                                          If you're not into dynamic (or aren't using .NET 4+), I like how this other answer relies solely on Json.NET's API.






                                          share|improve this answer




























                                            0












                                            0








                                            0







                                            string rap = JsonConvert.DeserializeObject<dynamic>(json).meta.rap;
                                            Console.WriteLine(rap); // 2098


                                            If you're not into dynamic (or aren't using .NET 4+), I like how this other answer relies solely on Json.NET's API.






                                            share|improve this answer















                                            string rap = JsonConvert.DeserializeObject<dynamic>(json).meta.rap;
                                            Console.WriteLine(rap); // 2098


                                            If you're not into dynamic (or aren't using .NET 4+), I like how this other answer relies solely on Json.NET's API.







                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited May 23 '17 at 12:24









                                            Community

                                            11




                                            11










                                            answered Jan 19 '17 at 23:05









                                            WilliamWilliam

                                            1,3101732




                                            1,3101732























                                                0














                                                Just use dynamic representation of object:



                                                dynamic obj = JsonConvert.DeserializeObject(json)
                                                var value = obj.meta.rap;


                                                JObject easily convertable to dynamic type itself. You can either get string or int from this value:



                                                var ivalue = (int)obj.meta.rap;
                                                var svalue = (string)obj.meta.rap;





                                                share|improve this answer






























                                                  0














                                                  Just use dynamic representation of object:



                                                  dynamic obj = JsonConvert.DeserializeObject(json)
                                                  var value = obj.meta.rap;


                                                  JObject easily convertable to dynamic type itself. You can either get string or int from this value:



                                                  var ivalue = (int)obj.meta.rap;
                                                  var svalue = (string)obj.meta.rap;





                                                  share|improve this answer




























                                                    0












                                                    0








                                                    0







                                                    Just use dynamic representation of object:



                                                    dynamic obj = JsonConvert.DeserializeObject(json)
                                                    var value = obj.meta.rap;


                                                    JObject easily convertable to dynamic type itself. You can either get string or int from this value:



                                                    var ivalue = (int)obj.meta.rap;
                                                    var svalue = (string)obj.meta.rap;





                                                    share|improve this answer















                                                    Just use dynamic representation of object:



                                                    dynamic obj = JsonConvert.DeserializeObject(json)
                                                    var value = obj.meta.rap;


                                                    JObject easily convertable to dynamic type itself. You can either get string or int from this value:



                                                    var ivalue = (int)obj.meta.rap;
                                                    var svalue = (string)obj.meta.rap;






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Jan 20 '17 at 6:35

























                                                    answered Jan 20 '17 at 6:22









                                                    eocroneocron

                                                    3,896835




                                                    3,896835























                                                        0














                                                        Try to use as following



                                                        var test = JsonConvert.DeserializeObject<dynamic>(param);

                                                        var testDTO = new TPRDTO();
                                                        testDTO.TPR_ID = test.TPR_ID.Value;


                                                        Note: For using of JsonConvert class you have to install Newton-Soft from your package-manager






                                                        share|improve this answer






























                                                          0














                                                          Try to use as following



                                                          var test = JsonConvert.DeserializeObject<dynamic>(param);

                                                          var testDTO = new TPRDTO();
                                                          testDTO.TPR_ID = test.TPR_ID.Value;


                                                          Note: For using of JsonConvert class you have to install Newton-Soft from your package-manager






                                                          share|improve this answer




























                                                            0












                                                            0








                                                            0







                                                            Try to use as following



                                                            var test = JsonConvert.DeserializeObject<dynamic>(param);

                                                            var testDTO = new TPRDTO();
                                                            testDTO.TPR_ID = test.TPR_ID.Value;


                                                            Note: For using of JsonConvert class you have to install Newton-Soft from your package-manager






                                                            share|improve this answer















                                                            Try to use as following



                                                            var test = JsonConvert.DeserializeObject<dynamic>(param);

                                                            var testDTO = new TPRDTO();
                                                            testDTO.TPR_ID = test.TPR_ID.Value;


                                                            Note: For using of JsonConvert class you have to install Newton-Soft from your package-manager







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Oct 10 '18 at 11:06









                                                            AmirReza-Farahlagha

                                                            594617




                                                            594617










                                                            answered Oct 10 '18 at 9:24









                                                            Srimitha VarshaSrimitha Varsha

                                                            1




                                                            1























                                                                0














                                                                the problem is that you are casting the deserialized json into a JObject. if you want to have the JObject then simple do this:



                                                                JObject.Parse(json); 


                                                                then you have the JObject and you can access a specific path (for extracting value see this )



                                                                you have also another option which is to deserialize your json into a class that you have in your code like this:



                                                                var instanceOFTheClass =  JsonConvert.DeserializeObject<YourClassName>(json); 


                                                                with the above code you can access any property and values you want.






                                                                share|improve this answer




























                                                                  0














                                                                  the problem is that you are casting the deserialized json into a JObject. if you want to have the JObject then simple do this:



                                                                  JObject.Parse(json); 


                                                                  then you have the JObject and you can access a specific path (for extracting value see this )



                                                                  you have also another option which is to deserialize your json into a class that you have in your code like this:



                                                                  var instanceOFTheClass =  JsonConvert.DeserializeObject<YourClassName>(json); 


                                                                  with the above code you can access any property and values you want.






                                                                  share|improve this answer


























                                                                    0












                                                                    0








                                                                    0







                                                                    the problem is that you are casting the deserialized json into a JObject. if you want to have the JObject then simple do this:



                                                                    JObject.Parse(json); 


                                                                    then you have the JObject and you can access a specific path (for extracting value see this )



                                                                    you have also another option which is to deserialize your json into a class that you have in your code like this:



                                                                    var instanceOFTheClass =  JsonConvert.DeserializeObject<YourClassName>(json); 


                                                                    with the above code you can access any property and values you want.






                                                                    share|improve this answer













                                                                    the problem is that you are casting the deserialized json into a JObject. if you want to have the JObject then simple do this:



                                                                    JObject.Parse(json); 


                                                                    then you have the JObject and you can access a specific path (for extracting value see this )



                                                                    you have also another option which is to deserialize your json into a class that you have in your code like this:



                                                                    var instanceOFTheClass =  JsonConvert.DeserializeObject<YourClassName>(json); 


                                                                    with the above code you can access any property and values you want.







                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Nov 23 '18 at 14:41









                                                                    MeysamMeysam

                                                                    180110




                                                                    180110






























                                                                        draft saved

                                                                        draft discarded




















































                                                                        Thanks for contributing an answer to Stack Overflow!


                                                                        • Please be sure to answer the question. Provide details and share your research!

                                                                        But avoid



                                                                        • Asking for help, clarification, or responding to other answers.

                                                                        • Making statements based on opinion; back them up with references or personal experience.


                                                                        To learn more, see our tips on writing great answers.




                                                                        draft saved


                                                                        draft discarded














                                                                        StackExchange.ready(
                                                                        function () {
                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41752928%2fc-sharp-get-value-from-deserialized-json-object%23new-answer', 'question_page');
                                                                        }
                                                                        );

                                                                        Post as a guest















                                                                        Required, but never shown





















































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown

































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown







                                                                        這個網誌中的熱門文章

                                                                        Xamarin.form Move up view when keyboard appear

                                                                        Post-Redirect-Get with Spring WebFlux and Thymeleaf

                                                                        Anylogic : not able to use stopDelay()