c# - Is it possible to deserialize and serialize json object in different propety names? -


let have class:

public class resource {     [jsonproperty(propertyname: "address")]     public domain.dto.address addresses { get; set; } }   

the json string value looks like:

{   .   .   .   "resourcesets":[      {         "estimatedtotal":1,         "resources":[            {               .               .               .               "address":{                  "userlocation":null,                  "admindistrict":"national capital region",                  "admindistrict2":"third district ncr",                  "locality":"caloocan city",                  "postalcode":null,                  "addressline":"yellow bell ext",                  "formattedaddress":"yellow bell ext, caloocan city, philippines",                  "neighborhood":"barangay 161",                  "landmark":null,                  "countryregion":"philippines"               }            }         ]      }   ] }   

this deserializes properly. when serializing resource class, want of properties 'addresses' serialized 'addresses' , not 'address'.

i have tried using datamember didn't work. idea?

[jsonproperty(propertyname: "address")] 

is making serialise "address".

remove attribute , it'll serialise c# property name.

string json = newtonsoft.json.jsonconvert.serializeobject(class); 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -