json - Deserialization and serialization using newtonsoft c# -
my application binding rest api, returns me:
{ key: "xxxx-xxxx", fields: { customfield_10913: { value: "l2" } } }
i'm using newtonsoft json serialize , deserialize , i've created these models make work:
public class issue { [jsonproperty("key")] public string key { get; set; } [jsonproperty("fields")] public fields fields { get; set; } } public class fields { [jsonproperty("customfield_10913")] public customfield level { get; set; } } public class customfield { [jsonproperty("value")] public string value{ get; set; } }
the application deserializing ok, using code:
t model = jsonconvert.deserializeobject<t>(result);
after lot of business logic, web api should return new json:
protected t get() { return model; }
and i've got json i've read api. so, need?
- i need read field custom_fieldxxx, can't return name in web api. how read field, when i'm doing serialization, assume one?
you may try below function
issue model = deserializeobject<issue>(result); public t deserializeobject<t>(string result) { try { var settings = new jsonserializersettings { formatting = formatting.indented, nullvaluehandling = newtonsoft.json.nullvaluehandling.ignore, defaultvaluehandling = defaultvaluehandling.ignore }; var items = (t)jsonconvert.deserializeobject(result, typeof(t), settings); return items; } catch (exception ex) { throw ex; } { } }
Comments
Post a Comment