Convert JSON string to simple object with json.net -
i using gson on client stringy object:
gson gson = new gson(); string data = gson.tojson(deviceinfo);
now receive in header of http request. need on server convert object. not parsing param modelbinder wont me. if there way manually use model binder. maybe option well.
how can json.net ?
basically want equivalent of: gson.fromjson(json, classoft)
the equivalent of gson.fromjson(json, classoft)
in json.net is
jsonconvert.deserializeobject<t>()
example:
public class account { public string email { get; set; } public bool active { get; set; } public datetime createddate { get; set; } public ilist<string> roles { get; set; } } string json = @"{ 'email': 'james@example.com', 'active': true, 'createddate': '2013-01-20t00:00:00z', 'roles': [ 'user', 'admin' ] }"; account account = jsonconvert.deserializeobject<account>(json); console.writeline(account.email);
Comments
Post a Comment