Here is a sample JSON string that I'm trying to deserialize:
{
"background": "#ededf0",
"theme": "Flat",
"name": "Control Page Name",
"scriptName": "Control Page Script",
"objects": [{
"ID": "76799598",
"position": {
"top": 0.30428571428571427,
"left": 0.6054421768707483
},
"width": 0.09451596023024594,
"height": 0.07450128571428571,
"label": "btn",
"colour": "blue",
"action": "OpenLayout",
"actionParams": {
"actionName": "Explorer",
"itemId": "91d5bfff-a723-498a-a846-24a9e41fbaa6",
"groupId": "bf434b0d-90c2-496a-96ce-c09f228255b4"
}
}]
}
I can't seem to iterate through the "objects" key node value of the JSON. Everything before words fine (background, theme,name and scriptName). Here's my converter
{
JObject panel = (JObject)serializer.Deserialize(reader);
var cpResponse = new VWControlPanelResponse();
JToken scriptGroupId, scriptId;
cpResponse.Background = (string)((JValue)panel["background"]).Value;
cpResponse.Theme = (string)((JValue)panel["theme"]).Value;
cpResponse.Name = (string)((JValue)panel["name"]).Value;
cpResponse.ScriptName = (string)((JValue)panel["scriptName"]).Value;
cpResponse.ScriptGroupId = panel.TryGetValue("scriptGroupId", out scriptGroupId) ? new Guid(scriptGroupId.ToString()) : Guid.Empty;
cpResponse.ScriptId = panel.TryGetValue("scriptId", out scriptId) ? new Guid(scriptId.ToString()) : Guid.Empty;
cpResponse.VisualElements = serializer.Deserialize<List<VisualElement>>(reader);
return cpResponse;
}
... and here are my models:
[JsonConverter(typeof(Converter))]
public class Response
{
public string Background { get; set; }
public string Theme { get; set; }
public string Name { get; set; }
public string ScriptName { get; set; }
public Guid ScriptGroupId { get; set; }
public Guid ScriptId { get; set; }
public List<VisualElement> VisualElements { get; set; }
}
public class VisualElement
{
public long ID { get; set; }
}
}
I've went through many similar articles online (this one in particular JSON Deserialization C# but I can't seem to figure out why it doesn't want to translate my VisualElements node. I tried using reader.Read() actions but the reader's token type indicates that it's an end of object.