c# - How to deserialize this json to a list of objects? -


i got json msg (don't pay attention encoding) :

{ "u1000 r2v": {     "carac1": ["câble d'alimentation rigide rond"],     "optionvj": ["oui"],     "carac4": [""],     "carac3": ["pour alimentation de ligne électrique", "pour alimentation des moteurs"] }, "h05 vvf": {     "carac1": ["câble souple rond"],     "optionvj": ["oui"],     "carac4": [""],     "carac3": ["pour câblage des sélecteurs à clé", "pour alimentation des lampe clignotantes"] } } 

i've tried objects :

public class typeproductlist {     public list<producttypedto> cables { get; set; } }   public class producttypedto {     public string[] carac1;     public string[] optionvj;     public string[] carac4;     public string[] carac3; } 

but doesn't work, don't know how because "parent element" (i mean u1000 r2v, h05 vvf) changing every object. structure should use deserialize list of producttypedto? thx

as anton noted in comment, should deserialize dictionary<string, producttypedto> first.

code (uses json.net):

var result = jsonconvert.deserializeobject<dictionary<string, producttypedto>>(json); var typeproductlist = new typeproductlist { cables = result.values.tolist(); } 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -