Create DataContract Class in c# from Json having Dynamically generated keys -


i have sample json :

{"'1234xxxxxx'":[{"attributeid":"1","attributename":"brand","attributevalue":""},{"attributeid":"2","attributename":"color","attributevalue":"red4"},{"attributeid":"3","attributename":"size","attributevalue":"44"},{"attributeid":"4","attributename":"resolution","attributevalue":"full hd"}]} 

i have created sample datacontract class :

  [system.runtime.serialization.datacontract] public  class rootobject {     [system.runtime.serialization.datamember]     public attr[] attrs { get; set; } }  [system.runtime.serialization.datacontract] public  class attr {     [system.runtime.serialization.datamember]     public string attributeid { get; set; }      [system.runtime.serialization.datamember]     public string attributename { get; set; }      [system.runtime.serialization.datamember]     public string attributevalue { get; set; }     } 

now , want access attributes using datacontractjsonserializer , memorystream, problem key '1234xxxxxx' in json dynamically generated everytime. how should access attributes in c# code?

if datacontractjsonserializer not hard requirement you, use json.net deserialize object:

jsonconvert.deserializeobject<idictionary<string, icollection<attr>>>(jsonstring); 

Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -