Convert JSON to C# POCO












-1















I have below JSON data



{
"appDesc": {
"description": "App description.",
"message": "Create and edit presentations "
},
"appName": {
"description": "App name.",
"message": "Slides"
}
}


I want to Deserialize into C# class object. I am using JsonConvert.DeserializeObject<>() to achieve this functionality. But some how it is not working.



 string JsonData= System.IO.File.ReadAllText(msgJSONpath);

var moreInfo = JsonConvert.DeserializeObject<appName>(msg)



internal class appName
{
public string message { get; set; }

public string description { get; set; }
}


So moreInfo object will have 2 properties in message and description.










share|improve this question




















  • 1





    show your class you want to de-serialize into

    – Just code
    Nov 20 '18 at 6:49











  • internal class appName { public string message { get; set; } public string description { get; set; } }

    – AMIT SHELKE
    Nov 20 '18 at 6:50











  • edit your question and add your relevant code

    – Just code
    Nov 20 '18 at 6:51











  • Senario is, when I read a .json file which is having above data, I need to convert them into objects. Something like I have mentioned above.

    – AMIT SHELKE
    Nov 20 '18 at 6:52











  • Add your code which you have tried

    – Rahul Neekhra
    Nov 20 '18 at 6:55
















-1















I have below JSON data



{
"appDesc": {
"description": "App description.",
"message": "Create and edit presentations "
},
"appName": {
"description": "App name.",
"message": "Slides"
}
}


I want to Deserialize into C# class object. I am using JsonConvert.DeserializeObject<>() to achieve this functionality. But some how it is not working.



 string JsonData= System.IO.File.ReadAllText(msgJSONpath);

var moreInfo = JsonConvert.DeserializeObject<appName>(msg)



internal class appName
{
public string message { get; set; }

public string description { get; set; }
}


So moreInfo object will have 2 properties in message and description.










share|improve this question




















  • 1





    show your class you want to de-serialize into

    – Just code
    Nov 20 '18 at 6:49











  • internal class appName { public string message { get; set; } public string description { get; set; } }

    – AMIT SHELKE
    Nov 20 '18 at 6:50











  • edit your question and add your relevant code

    – Just code
    Nov 20 '18 at 6:51











  • Senario is, when I read a .json file which is having above data, I need to convert them into objects. Something like I have mentioned above.

    – AMIT SHELKE
    Nov 20 '18 at 6:52











  • Add your code which you have tried

    – Rahul Neekhra
    Nov 20 '18 at 6:55














-1












-1








-1








I have below JSON data



{
"appDesc": {
"description": "App description.",
"message": "Create and edit presentations "
},
"appName": {
"description": "App name.",
"message": "Slides"
}
}


I want to Deserialize into C# class object. I am using JsonConvert.DeserializeObject<>() to achieve this functionality. But some how it is not working.



 string JsonData= System.IO.File.ReadAllText(msgJSONpath);

var moreInfo = JsonConvert.DeserializeObject<appName>(msg)



internal class appName
{
public string message { get; set; }

public string description { get; set; }
}


So moreInfo object will have 2 properties in message and description.










share|improve this question
















I have below JSON data



{
"appDesc": {
"description": "App description.",
"message": "Create and edit presentations "
},
"appName": {
"description": "App name.",
"message": "Slides"
}
}


I want to Deserialize into C# class object. I am using JsonConvert.DeserializeObject<>() to achieve this functionality. But some how it is not working.



 string JsonData= System.IO.File.ReadAllText(msgJSONpath);

var moreInfo = JsonConvert.DeserializeObject<appName>(msg)



internal class appName
{
public string message { get; set; }

public string description { get; set; }
}


So moreInfo object will have 2 properties in message and description.







c# json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 7:58









JustLearning

1,13821637




1,13821637










asked Nov 20 '18 at 6:48









AMIT SHELKEAMIT SHELKE

2073923




2073923








  • 1





    show your class you want to de-serialize into

    – Just code
    Nov 20 '18 at 6:49











  • internal class appName { public string message { get; set; } public string description { get; set; } }

    – AMIT SHELKE
    Nov 20 '18 at 6:50











  • edit your question and add your relevant code

    – Just code
    Nov 20 '18 at 6:51











  • Senario is, when I read a .json file which is having above data, I need to convert them into objects. Something like I have mentioned above.

    – AMIT SHELKE
    Nov 20 '18 at 6:52











  • Add your code which you have tried

    – Rahul Neekhra
    Nov 20 '18 at 6:55














  • 1





    show your class you want to de-serialize into

    – Just code
    Nov 20 '18 at 6:49











  • internal class appName { public string message { get; set; } public string description { get; set; } }

    – AMIT SHELKE
    Nov 20 '18 at 6:50











  • edit your question and add your relevant code

    – Just code
    Nov 20 '18 at 6:51











  • Senario is, when I read a .json file which is having above data, I need to convert them into objects. Something like I have mentioned above.

    – AMIT SHELKE
    Nov 20 '18 at 6:52











  • Add your code which you have tried

    – Rahul Neekhra
    Nov 20 '18 at 6:55








1




1





show your class you want to de-serialize into

– Just code
Nov 20 '18 at 6:49





show your class you want to de-serialize into

– Just code
Nov 20 '18 at 6:49













internal class appName { public string message { get; set; } public string description { get; set; } }

– AMIT SHELKE
Nov 20 '18 at 6:50





internal class appName { public string message { get; set; } public string description { get; set; } }

– AMIT SHELKE
Nov 20 '18 at 6:50













edit your question and add your relevant code

– Just code
Nov 20 '18 at 6:51





edit your question and add your relevant code

– Just code
Nov 20 '18 at 6:51













Senario is, when I read a .json file which is having above data, I need to convert them into objects. Something like I have mentioned above.

– AMIT SHELKE
Nov 20 '18 at 6:52





Senario is, when I read a .json file which is having above data, I need to convert them into objects. Something like I have mentioned above.

– AMIT SHELKE
Nov 20 '18 at 6:52













Add your code which you have tried

– Rahul Neekhra
Nov 20 '18 at 6:55





Add your code which you have tried

– Rahul Neekhra
Nov 20 '18 at 6:55












3 Answers
3






active

oldest

votes


















0














JObject defines method Parse for this:



JObject json = JObject.Parse(str);


or try for a typed object try:



Foo json  = JsonConvert.DeserializeObject<Foo>(str)





share|improve this answer































    0














    you need 2 C# classes since the properties of appName and appDesc are exactly the same.





    1. To store appname



      public class appName {
      public string description { get; set; }
      public string message { get; set; }
      }



    2. A class to have both above classes as properties



      public class appResult {
      public appName appDesc { get; set; }
      public appName appName { get; set; }

      public appResult() {
      appDesc = new appName();
      appName = new appName();
      }
      }
      }



    3. desirialize the json



      var result = JsonConvert.DeserializeObject<appResult>(msg);



    4. Once you have the result object you can get your appName



      var appName = result.appName;







    share|improve this answer





















    • 1





      appName and appDesc are the same. There's no reason to use separate classes for them

      – Panagiotis Kanavos
      Nov 20 '18 at 7:50











    • i see your point your are right

      – JustLearning
      Nov 20 '18 at 7:59











    • @BackSlash i just saw it now, why it makes sense

      – JustLearning
      Nov 20 '18 at 8:00



















    0














    First ,you need to create some classes based on your JSON , if you,re using visual studio you can copy the JSON string to your clipboard and than go to



    Edit > Paste Special > Paste JSON As Classes



    otherwise you can use This Online Tool



    after that your code should be something like this :



         string JsonData= System.IO.File.ReadAllText(msgJSONpath);

    var moreInfo = JsonConvert.DeserializeObject<RootObject>(msg);


    Generated Classes Based On Your JSON :



        public class AppDesc
    {
    public string description { get; set; }
    public string message { get; set; }
    }

    public class AppName
    {
    public string description { get; set; }
    public string message { get; set; }
    }

    public class RootObject
    {
    public AppDesc appDesc { get; set; }
    public AppName appName { get; set; }
    }





    share|improve this answer





















    • 1





      This would be a good answer if you pasted the generated classes as well

      – Panagiotis Kanavos
      Nov 20 '18 at 7:50











    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%2f53387635%2fconvert-json-to-c-sharp-poco%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    JObject defines method Parse for this:



    JObject json = JObject.Parse(str);


    or try for a typed object try:



    Foo json  = JsonConvert.DeserializeObject<Foo>(str)





    share|improve this answer




























      0














      JObject defines method Parse for this:



      JObject json = JObject.Parse(str);


      or try for a typed object try:



      Foo json  = JsonConvert.DeserializeObject<Foo>(str)





      share|improve this answer


























        0












        0








        0







        JObject defines method Parse for this:



        JObject json = JObject.Parse(str);


        or try for a typed object try:



        Foo json  = JsonConvert.DeserializeObject<Foo>(str)





        share|improve this answer













        JObject defines method Parse for this:



        JObject json = JObject.Parse(str);


        or try for a typed object try:



        Foo json  = JsonConvert.DeserializeObject<Foo>(str)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 6:58









        A.M. PatelA.M. Patel

        689




        689

























            0














            you need 2 C# classes since the properties of appName and appDesc are exactly the same.





            1. To store appname



              public class appName {
              public string description { get; set; }
              public string message { get; set; }
              }



            2. A class to have both above classes as properties



              public class appResult {
              public appName appDesc { get; set; }
              public appName appName { get; set; }

              public appResult() {
              appDesc = new appName();
              appName = new appName();
              }
              }
              }



            3. desirialize the json



              var result = JsonConvert.DeserializeObject<appResult>(msg);



            4. Once you have the result object you can get your appName



              var appName = result.appName;







            share|improve this answer





















            • 1





              appName and appDesc are the same. There's no reason to use separate classes for them

              – Panagiotis Kanavos
              Nov 20 '18 at 7:50











            • i see your point your are right

              – JustLearning
              Nov 20 '18 at 7:59











            • @BackSlash i just saw it now, why it makes sense

              – JustLearning
              Nov 20 '18 at 8:00
















            0














            you need 2 C# classes since the properties of appName and appDesc are exactly the same.





            1. To store appname



              public class appName {
              public string description { get; set; }
              public string message { get; set; }
              }



            2. A class to have both above classes as properties



              public class appResult {
              public appName appDesc { get; set; }
              public appName appName { get; set; }

              public appResult() {
              appDesc = new appName();
              appName = new appName();
              }
              }
              }



            3. desirialize the json



              var result = JsonConvert.DeserializeObject<appResult>(msg);



            4. Once you have the result object you can get your appName



              var appName = result.appName;







            share|improve this answer





















            • 1





              appName and appDesc are the same. There's no reason to use separate classes for them

              – Panagiotis Kanavos
              Nov 20 '18 at 7:50











            • i see your point your are right

              – JustLearning
              Nov 20 '18 at 7:59











            • @BackSlash i just saw it now, why it makes sense

              – JustLearning
              Nov 20 '18 at 8:00














            0












            0








            0







            you need 2 C# classes since the properties of appName and appDesc are exactly the same.





            1. To store appname



              public class appName {
              public string description { get; set; }
              public string message { get; set; }
              }



            2. A class to have both above classes as properties



              public class appResult {
              public appName appDesc { get; set; }
              public appName appName { get; set; }

              public appResult() {
              appDesc = new appName();
              appName = new appName();
              }
              }
              }



            3. desirialize the json



              var result = JsonConvert.DeserializeObject<appResult>(msg);



            4. Once you have the result object you can get your appName



              var appName = result.appName;







            share|improve this answer















            you need 2 C# classes since the properties of appName and appDesc are exactly the same.





            1. To store appname



              public class appName {
              public string description { get; set; }
              public string message { get; set; }
              }



            2. A class to have both above classes as properties



              public class appResult {
              public appName appDesc { get; set; }
              public appName appName { get; set; }

              public appResult() {
              appDesc = new appName();
              appName = new appName();
              }
              }
              }



            3. desirialize the json



              var result = JsonConvert.DeserializeObject<appResult>(msg);



            4. Once you have the result object you can get your appName



              var appName = result.appName;








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 20 '18 at 8:01

























            answered Nov 20 '18 at 7:04









            JustLearningJustLearning

            1,13821637




            1,13821637








            • 1





              appName and appDesc are the same. There's no reason to use separate classes for them

              – Panagiotis Kanavos
              Nov 20 '18 at 7:50











            • i see your point your are right

              – JustLearning
              Nov 20 '18 at 7:59











            • @BackSlash i just saw it now, why it makes sense

              – JustLearning
              Nov 20 '18 at 8:00














            • 1





              appName and appDesc are the same. There's no reason to use separate classes for them

              – Panagiotis Kanavos
              Nov 20 '18 at 7:50











            • i see your point your are right

              – JustLearning
              Nov 20 '18 at 7:59











            • @BackSlash i just saw it now, why it makes sense

              – JustLearning
              Nov 20 '18 at 8:00








            1




            1





            appName and appDesc are the same. There's no reason to use separate classes for them

            – Panagiotis Kanavos
            Nov 20 '18 at 7:50





            appName and appDesc are the same. There's no reason to use separate classes for them

            – Panagiotis Kanavos
            Nov 20 '18 at 7:50













            i see your point your are right

            – JustLearning
            Nov 20 '18 at 7:59





            i see your point your are right

            – JustLearning
            Nov 20 '18 at 7:59













            @BackSlash i just saw it now, why it makes sense

            – JustLearning
            Nov 20 '18 at 8:00





            @BackSlash i just saw it now, why it makes sense

            – JustLearning
            Nov 20 '18 at 8:00











            0














            First ,you need to create some classes based on your JSON , if you,re using visual studio you can copy the JSON string to your clipboard and than go to



            Edit > Paste Special > Paste JSON As Classes



            otherwise you can use This Online Tool



            after that your code should be something like this :



                 string JsonData= System.IO.File.ReadAllText(msgJSONpath);

            var moreInfo = JsonConvert.DeserializeObject<RootObject>(msg);


            Generated Classes Based On Your JSON :



                public class AppDesc
            {
            public string description { get; set; }
            public string message { get; set; }
            }

            public class AppName
            {
            public string description { get; set; }
            public string message { get; set; }
            }

            public class RootObject
            {
            public AppDesc appDesc { get; set; }
            public AppName appName { get; set; }
            }





            share|improve this answer





















            • 1





              This would be a good answer if you pasted the generated classes as well

              – Panagiotis Kanavos
              Nov 20 '18 at 7:50
















            0














            First ,you need to create some classes based on your JSON , if you,re using visual studio you can copy the JSON string to your clipboard and than go to



            Edit > Paste Special > Paste JSON As Classes



            otherwise you can use This Online Tool



            after that your code should be something like this :



                 string JsonData= System.IO.File.ReadAllText(msgJSONpath);

            var moreInfo = JsonConvert.DeserializeObject<RootObject>(msg);


            Generated Classes Based On Your JSON :



                public class AppDesc
            {
            public string description { get; set; }
            public string message { get; set; }
            }

            public class AppName
            {
            public string description { get; set; }
            public string message { get; set; }
            }

            public class RootObject
            {
            public AppDesc appDesc { get; set; }
            public AppName appName { get; set; }
            }





            share|improve this answer





















            • 1





              This would be a good answer if you pasted the generated classes as well

              – Panagiotis Kanavos
              Nov 20 '18 at 7:50














            0












            0








            0







            First ,you need to create some classes based on your JSON , if you,re using visual studio you can copy the JSON string to your clipboard and than go to



            Edit > Paste Special > Paste JSON As Classes



            otherwise you can use This Online Tool



            after that your code should be something like this :



                 string JsonData= System.IO.File.ReadAllText(msgJSONpath);

            var moreInfo = JsonConvert.DeserializeObject<RootObject>(msg);


            Generated Classes Based On Your JSON :



                public class AppDesc
            {
            public string description { get; set; }
            public string message { get; set; }
            }

            public class AppName
            {
            public string description { get; set; }
            public string message { get; set; }
            }

            public class RootObject
            {
            public AppDesc appDesc { get; set; }
            public AppName appName { get; set; }
            }





            share|improve this answer















            First ,you need to create some classes based on your JSON , if you,re using visual studio you can copy the JSON string to your clipboard and than go to



            Edit > Paste Special > Paste JSON As Classes



            otherwise you can use This Online Tool



            after that your code should be something like this :



                 string JsonData= System.IO.File.ReadAllText(msgJSONpath);

            var moreInfo = JsonConvert.DeserializeObject<RootObject>(msg);


            Generated Classes Based On Your JSON :



                public class AppDesc
            {
            public string description { get; set; }
            public string message { get; set; }
            }

            public class AppName
            {
            public string description { get; set; }
            public string message { get; set; }
            }

            public class RootObject
            {
            public AppDesc appDesc { get; set; }
            public AppName appName { get; set; }
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 20 '18 at 8:01

























            answered Nov 20 '18 at 7:43









            FarhadMohseniFarhadMohseni

            215




            215








            • 1





              This would be a good answer if you pasted the generated classes as well

              – Panagiotis Kanavos
              Nov 20 '18 at 7:50














            • 1





              This would be a good answer if you pasted the generated classes as well

              – Panagiotis Kanavos
              Nov 20 '18 at 7:50








            1




            1





            This would be a good answer if you pasted the generated classes as well

            – Panagiotis Kanavos
            Nov 20 '18 at 7:50





            This would be a good answer if you pasted the generated classes as well

            – Panagiotis Kanavos
            Nov 20 '18 at 7:50


















            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%2f53387635%2fconvert-json-to-c-sharp-poco%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







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini