javascript - deserialize nested json object in c# -
javascript - deserialize nested json object in c# -
i have json object in javascript
{"categoryid":"1","countryid":"1","countryname":"united arab emirates", "billerid":"23","accountno":"1234567890", "authenticators":"{\"consumernumber\":\"1234567890\",\"lastbilldate\":\"14-10-2014\",\"lastbillduedate\":\"24-11-2014\"}", "shortname":"0000000001"}
i have similar c# class as
[serializable] public class usercontext { public string categoryid { get; set; } public string billerid { get; set; } public string accountno { get; set; } public string authenticators { get; set; } public string shortname { get; set; } public string countryid { get; set; } public string countryname { get; set; } }
i can each element value in c# as
usercontext obj1 = deserialize<usercontext>(context);
but authenticators
nested json object want in c#
[serializable] public class authenticators { public string consumernumber { get; set; } public string lastbilldate { get; set; } public string lastbillduedate { get; set; } }
so can each value of each authenticators
element like
string value = obj.consumernumber;
i want populate 2 classes values. how can accomplish same ?
your usercontext class has string field authenticators, while json construction suggests it's object.
change
public string authenticators { get; set; }
to
public authenticators authenticators { get; set; }
then can deserialize usercontext object along nested object authenticators
usercontext obj1 = deserialize<usercontext>(context); var consumernumber = obj1.authenticators.consumernumber;
update:
you need prepare javascript code, bacause stores serialized json string string field within usercontext object.
what have now, similar to:
var info = { categoryid:"1", authenticators: json.stringify({consumernumber:"1234567890"}) }; var json = json.stringify(data);
it should like:
var info = { categoryid:"1", authenticators:{consumernumber:"1234567890"} }; var json = json.stringify(data);
javascript c# json
Comments
Post a Comment