Wednesday, 15 January 2014

c# - JSon Deserializing getting type -



c# - JSon Deserializing getting type -

class programme { static void main(string[] args) { string json = jsonconvert.serializeobject(new business relationship { name = "test" }, newtonsoft.json.formatting.indented, new jsonserializersettings { typenamehandling = typenamehandling.all,preservereferenceshandling = preservereferenceshandling.objects }); console.out.write(json); while (true) {} } } class business relationship { public string name; }

hey, im trying json. want deserialize object. want type info out of string. when deserialize want json recognize type without specifying it. possible?

best regards, brian

json.net unfortunately can't infer type json, if operate on json objects dynamically, check out jtoken, jobject, , jarray types newtonsoft.json.linq namespace. can read json path so

var myobject = jobject.parse(jsonstring) var someobject = myobject["myotherobject"]["otherthing"]; var mystring = (string) someobject["thestring"];

i find part of json.net useful , hope helps :)

c# .net json

No comments:

Post a Comment