Deserialize objectname to property in a more gerneric class [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • How can I parse a JSON string that would cause illegal C# identifiers?

    2 answers



  • Create a strongly typed c# object from json object with ID as the name

    1 answer



  • Json.NET - format an array of objects with names

    2 answers




Given JSON-Response with this structure



{
"Foo":{
"description":"lorem",
"weight":"0"
},
"Bar":{
"description":"ipsum",
"weight":"1"
},
"Baz":{
"description":"nunquet",
"weight":"2"
},
}


If I use the VisualStudio-Special-Paste I get a class for each object above, and a class 'root-item' with properties Foo, Bar and Baz.
I know already that there will be more items with the same structure in the future.



Is it possible to deserialize this to a list of instances of one class (with name/description/weight as properties), so that the objectname (Foo, Bar, Baz) will be the value of added property "name"?
Maybe it is obvious but I can't find an example in the documentation about this.










share|improve this question















marked as duplicate by dbc c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 17:59


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Deserialize to a Dictionary<string, Item> for some appropriate type Item as shown in How can I parse a JSON string that would cause illegal C# identifiers? or Create a strongly typed c# object from json object with ID as the name or Json.NET - format an array of objects with names. In fact I think it's a duplicate, agree?
    – dbc
    Nov 19 at 17:48












  • Yes, that works and it's a duplicate.
    – RuNe
    Nov 19 at 17:58















up vote
0
down vote

favorite













This question already has an answer here:




  • How can I parse a JSON string that would cause illegal C# identifiers?

    2 answers



  • Create a strongly typed c# object from json object with ID as the name

    1 answer



  • Json.NET - format an array of objects with names

    2 answers




Given JSON-Response with this structure



{
"Foo":{
"description":"lorem",
"weight":"0"
},
"Bar":{
"description":"ipsum",
"weight":"1"
},
"Baz":{
"description":"nunquet",
"weight":"2"
},
}


If I use the VisualStudio-Special-Paste I get a class for each object above, and a class 'root-item' with properties Foo, Bar and Baz.
I know already that there will be more items with the same structure in the future.



Is it possible to deserialize this to a list of instances of one class (with name/description/weight as properties), so that the objectname (Foo, Bar, Baz) will be the value of added property "name"?
Maybe it is obvious but I can't find an example in the documentation about this.










share|improve this question















marked as duplicate by dbc c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 17:59


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Deserialize to a Dictionary<string, Item> for some appropriate type Item as shown in How can I parse a JSON string that would cause illegal C# identifiers? or Create a strongly typed c# object from json object with ID as the name or Json.NET - format an array of objects with names. In fact I think it's a duplicate, agree?
    – dbc
    Nov 19 at 17:48












  • Yes, that works and it's a duplicate.
    – RuNe
    Nov 19 at 17:58













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • How can I parse a JSON string that would cause illegal C# identifiers?

    2 answers



  • Create a strongly typed c# object from json object with ID as the name

    1 answer



  • Json.NET - format an array of objects with names

    2 answers




Given JSON-Response with this structure



{
"Foo":{
"description":"lorem",
"weight":"0"
},
"Bar":{
"description":"ipsum",
"weight":"1"
},
"Baz":{
"description":"nunquet",
"weight":"2"
},
}


If I use the VisualStudio-Special-Paste I get a class for each object above, and a class 'root-item' with properties Foo, Bar and Baz.
I know already that there will be more items with the same structure in the future.



Is it possible to deserialize this to a list of instances of one class (with name/description/weight as properties), so that the objectname (Foo, Bar, Baz) will be the value of added property "name"?
Maybe it is obvious but I can't find an example in the documentation about this.










share|improve this question
















This question already has an answer here:




  • How can I parse a JSON string that would cause illegal C# identifiers?

    2 answers



  • Create a strongly typed c# object from json object with ID as the name

    1 answer



  • Json.NET - format an array of objects with names

    2 answers




Given JSON-Response with this structure



{
"Foo":{
"description":"lorem",
"weight":"0"
},
"Bar":{
"description":"ipsum",
"weight":"1"
},
"Baz":{
"description":"nunquet",
"weight":"2"
},
}


If I use the VisualStudio-Special-Paste I get a class for each object above, and a class 'root-item' with properties Foo, Bar and Baz.
I know already that there will be more items with the same structure in the future.



Is it possible to deserialize this to a list of instances of one class (with name/description/weight as properties), so that the objectname (Foo, Bar, Baz) will be the value of added property "name"?
Maybe it is obvious but I can't find an example in the documentation about this.





This question already has an answer here:




  • How can I parse a JSON string that would cause illegal C# identifiers?

    2 answers



  • Create a strongly typed c# object from json object with ID as the name

    1 answer



  • Json.NET - format an array of objects with names

    2 answers








c# parsing json.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 18:01









Frontear

426313




426313










asked Nov 19 at 17:47









RuNe

265




265




marked as duplicate by dbc c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 17:59


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by dbc c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 at 17:59


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Deserialize to a Dictionary<string, Item> for some appropriate type Item as shown in How can I parse a JSON string that would cause illegal C# identifiers? or Create a strongly typed c# object from json object with ID as the name or Json.NET - format an array of objects with names. In fact I think it's a duplicate, agree?
    – dbc
    Nov 19 at 17:48












  • Yes, that works and it's a duplicate.
    – RuNe
    Nov 19 at 17:58


















  • Deserialize to a Dictionary<string, Item> for some appropriate type Item as shown in How can I parse a JSON string that would cause illegal C# identifiers? or Create a strongly typed c# object from json object with ID as the name or Json.NET - format an array of objects with names. In fact I think it's a duplicate, agree?
    – dbc
    Nov 19 at 17:48












  • Yes, that works and it's a duplicate.
    – RuNe
    Nov 19 at 17:58
















Deserialize to a Dictionary<string, Item> for some appropriate type Item as shown in How can I parse a JSON string that would cause illegal C# identifiers? or Create a strongly typed c# object from json object with ID as the name or Json.NET - format an array of objects with names. In fact I think it's a duplicate, agree?
– dbc
Nov 19 at 17:48






Deserialize to a Dictionary<string, Item> for some appropriate type Item as shown in How can I parse a JSON string that would cause illegal C# identifiers? or Create a strongly typed c# object from json object with ID as the name or Json.NET - format an array of objects with names. In fact I think it's a duplicate, agree?
– dbc
Nov 19 at 17:48














Yes, that works and it's a duplicate.
– RuNe
Nov 19 at 17:58




Yes, that works and it's a duplicate.
– RuNe
Nov 19 at 17:58

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy