I am new to Json, so a bit green.
I have a rest-based service that returns a json string;
{"treeNode":[{"id":"U-2905","pid":"R","userId":"2905"}, {"id":"U-2905","pid":"R","userId":"2905"}]}
I played with Json.net and am trying to deserialize a string into Object, etc. I wrote an extension method to help.
public static T DeserializeFromJSON<T>(this Stream jsonStream, Type objectType) { T result; using (StreamReader reader = new StreamReader(jsonStream)) { JsonSerializer serializer = new JsonSerializer(); try { result = (T)serializer.Deserialize(reader, objectType); } catch (Exception e) { throw; } } return result; }
I was expecting an array of treeNode [] objects. But it seems that I can only deserialize correctly if the treeNode [] property of another object.
public class treeNode { public string id { get; set; } public string pid { get; set; } public string userId { get; set; } }
Do I have a way to just get a direct array from deserialization?
Greetings
76mel source share