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
Post a Comment