Convert JSON to C# POCO
up vote
-1
down vote
favorite
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
up vote
-1
down vote
favorite
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 at 6:49
internal class appName { public string message { get; set; } public string description { get; set; } }
– AMIT SHELKE
Nov 20 at 6:50
edit your question and add your relevant code
– Just code
Nov 20 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 at 6:52
Add your code which you have tried
– Rahul Neekhra
Nov 20 at 6:55
|
show 4 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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 at 7:58
JustLearning
94921634
94921634
asked Nov 20 at 6:48
AMIT SHELKE
2023923
2023923
1
show your class you want to de-serialize into
– Just code
Nov 20 at 6:49
internal class appName { public string message { get; set; } public string description { get; set; } }
– AMIT SHELKE
Nov 20 at 6:50
edit your question and add your relevant code
– Just code
Nov 20 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 at 6:52
Add your code which you have tried
– Rahul Neekhra
Nov 20 at 6:55
|
show 4 more comments
1
show your class you want to de-serialize into
– Just code
Nov 20 at 6:49
internal class appName { public string message { get; set; } public string description { get; set; } }
– AMIT SHELKE
Nov 20 at 6:50
edit your question and add your relevant code
– Just code
Nov 20 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 at 6:52
Add your code which you have tried
– Rahul Neekhra
Nov 20 at 6:55
1
1
show your class you want to de-serialize into
– Just code
Nov 20 at 6:49
show your class you want to de-serialize into
– Just code
Nov 20 at 6:49
internal class appName { public string message { get; set; } public string description { get; set; } }
– AMIT SHELKE
Nov 20 at 6:50
internal class appName { public string message { get; set; } public string description { get; set; } }
– AMIT SHELKE
Nov 20 at 6:50
edit your question and add your relevant code
– Just code
Nov 20 at 6:51
edit your question and add your relevant code
– Just code
Nov 20 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 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 at 6:52
Add your code which you have tried
– Rahul Neekhra
Nov 20 at 6:55
Add your code which you have tried
– Rahul Neekhra
Nov 20 at 6:55
|
show 4 more comments
3 Answers
3
active
oldest
votes
up vote
0
down vote
accepted
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 |
up vote
0
down vote
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 at 7:50
i see your point your are right
– JustLearning
Nov 20 at 7:59
@BackSlash i just saw it now, why it makes sense
– JustLearning
Nov 20 at 8:00
add a comment |
up vote
0
down vote
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 at 7:50
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
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 |
up vote
0
down vote
accepted
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 |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
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 at 6:58
user2156791
628
628
add a comment |
add a comment |
up vote
0
down vote
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 at 7:50
i see your point your are right
– JustLearning
Nov 20 at 7:59
@BackSlash i just saw it now, why it makes sense
– JustLearning
Nov 20 at 8:00
add a comment |
up vote
0
down vote
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 at 7:50
i see your point your are right
– JustLearning
Nov 20 at 7:59
@BackSlash i just saw it now, why it makes sense
– JustLearning
Nov 20 at 8:00
add a comment |
up vote
0
down vote
up vote
0
down vote
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 at 8:01
answered Nov 20 at 7:04
JustLearning
94921634
94921634
1
appName
andappDesc
are the same. There's no reason to use separate classes for them
– Panagiotis Kanavos
Nov 20 at 7:50
i see your point your are right
– JustLearning
Nov 20 at 7:59
@BackSlash i just saw it now, why it makes sense
– JustLearning
Nov 20 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 at 7:50
i see your point your are right
– JustLearning
Nov 20 at 7:59
@BackSlash i just saw it now, why it makes sense
– JustLearning
Nov 20 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 at 7:50
appName
and appDesc
are the same. There's no reason to use separate classes for them– Panagiotis Kanavos
Nov 20 at 7:50
i see your point your are right
– JustLearning
Nov 20 at 7:59
i see your point your are right
– JustLearning
Nov 20 at 7:59
@BackSlash i just saw it now, why it makes sense
– JustLearning
Nov 20 at 8:00
@BackSlash i just saw it now, why it makes sense
– JustLearning
Nov 20 at 8:00
add a comment |
up vote
0
down vote
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 at 7:50
add a comment |
up vote
0
down vote
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 at 7:50
add a comment |
up vote
0
down vote
up vote
0
down vote
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 at 8:01
answered Nov 20 at 7:43
FarhadMohseni
215
215
1
This would be a good answer if you pasted the generated classes as well
– Panagiotis Kanavos
Nov 20 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 at 7:50
1
1
This would be a good answer if you pasted the generated classes as well
– Panagiotis Kanavos
Nov 20 at 7:50
This would be a good answer if you pasted the generated classes as well
– Panagiotis Kanavos
Nov 20 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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 at 6:49
internal class appName { public string message { get; set; } public string description { get; set; } }
– AMIT SHELKE
Nov 20 at 6:50
edit your question and add your relevant code
– Just code
Nov 20 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 at 6:52
Add your code which you have tried
– Rahul Neekhra
Nov 20 at 6:55