Convert JSON to C# POCO
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
|
show 4 more comments
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
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
|
show 4 more comments
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
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
c# json
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
|
show 4 more comments
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
|
show 4 more comments
3 Answers
3
active
oldest
votes
JObject defines method Parse for this:
JObject json = JObject.Parse(str);
or try for a typed object try:
Foo json = JsonConvert.DeserializeObject<Foo>(str)
add a comment |
you need 2 C# classes since the properties of appName and appDesc are exactly the same.
To store appname
public class appName {
public string description { get; set; }
public string message { get; set; }
}
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();
}
}
}
desirialize the json
var result = JsonConvert.DeserializeObject<appResult>(msg);
Once you have the result object you can get your
appName
var appName = result.appName;
1
appName
andappDesc
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
add a comment |
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; }
}
1
This would be a good answer if you pasted the generated classes as well
– Panagiotis Kanavos
Nov 20 '18 at 7:50
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
JObject defines method Parse for this:
JObject json = JObject.Parse(str);
or try for a typed object try:
Foo json = JsonConvert.DeserializeObject<Foo>(str)
add a comment |
JObject defines method Parse for this:
JObject json = JObject.Parse(str);
or try for a typed object try:
Foo json = JsonConvert.DeserializeObject<Foo>(str)
add a comment |
JObject defines method Parse for this:
JObject json = JObject.Parse(str);
or try for a typed object try:
Foo json = JsonConvert.DeserializeObject<Foo>(str)
JObject defines method Parse for this:
JObject json = JObject.Parse(str);
or try for a typed object try:
Foo json = JsonConvert.DeserializeObject<Foo>(str)
answered Nov 20 '18 at 6:58
A.M. PatelA.M. Patel
689
689
add a comment |
add a comment |
you need 2 C# classes since the properties of appName and appDesc are exactly the same.
To store appname
public class appName {
public string description { get; set; }
public string message { get; set; }
}
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();
}
}
}
desirialize the json
var result = JsonConvert.DeserializeObject<appResult>(msg);
Once you have the result object you can get your
appName
var appName = result.appName;
1
appName
andappDesc
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
add a comment |
you need 2 C# classes since the properties of appName and appDesc are exactly the same.
To store appname
public class appName {
public string description { get; set; }
public string message { get; set; }
}
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();
}
}
}
desirialize the json
var result = JsonConvert.DeserializeObject<appResult>(msg);
Once you have the result object you can get your
appName
var appName = result.appName;
1
appName
andappDesc
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
add a comment |
you need 2 C# classes since the properties of appName and appDesc are exactly the same.
To store appname
public class appName {
public string description { get; set; }
public string message { get; set; }
}
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();
}
}
}
desirialize the json
var result = JsonConvert.DeserializeObject<appResult>(msg);
Once you have the result object you can get your
appName
var appName = result.appName;
you need 2 C# classes since the properties of appName and appDesc are exactly the same.
To store appname
public class appName {
public string description { get; set; }
public string message { get; set; }
}
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();
}
}
}
desirialize the json
var result = JsonConvert.DeserializeObject<appResult>(msg);
Once you have the result object you can get your
appName
var appName = result.appName;
edited Nov 20 '18 at 8:01
answered Nov 20 '18 at 7:04
JustLearningJustLearning
1,13821637
1,13821637
1
appName
andappDesc
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
add a comment |
1
appName
andappDesc
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
add a comment |
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; }
}
1
This would be a good answer if you pasted the generated classes as well
– Panagiotis Kanavos
Nov 20 '18 at 7:50
add a comment |
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; }
}
1
This would be a good answer if you pasted the generated classes as well
– Panagiotis Kanavos
Nov 20 '18 at 7:50
add a comment |
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; }
}
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; }
}
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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