I have this JSON Object (FabricJS) that I want to de-serialize with JSON.NET on a POST request:
"{\"objects\":[{\"type\":\"OpenLayout\",\"originX\":\"left\",\"originY\":\"top\",\"left\":300,\"top\":203,\"width\":200,\"height\":100,\"fill\":\"#f05a30\",\"stroke\":null,\"strokeWidth\":1,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeLineJoin\":\"miter\",\"strokeMiterLimit\":10,\"scaleX\":1,\"scaleY\":1,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"clipTo\":null,\"backgroundColor\":\"\",\"rx\":0,\"ry\":0,\"x\":0,\"y\":0,\"label\":\"btn1\"},{\"type\":\"OpenLayout\",\"originX\":\"left\",\"originY\":\"top\",\"left\":13,\"top\":335,\"width\":200,\"height\":100,\"fill\":\"#f05a30\",\"stroke\":null,\"strokeWidth\":1,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeLineJoin\":\"miter\",\"strokeMiterLimit\":10,\"scaleX\":1,\"scaleY\":1,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"clipTo\":null,\"backgroundColor\":\"\",\"rx\":0,\"ry\":0,\"x\":0,\"y\":0,\"label\":\"\"}],\"background\":\"\"}"
Here is the class representing the structure:
public partial class ControlPageResponse
{
[JsonProperty("objects")]
public CanvasBtns[] Btns { get; set; }
[JsonProperty("background")]
public string Background { get; set; }
}
public class CanvasBtns
{
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("originX")]
public string OriginX { get; set; }
[JsonProperty("originY")]
public string OriginY { get; set; }
[JsonProperty("left")]
public int Left { get; set; }
[JsonProperty("top")]
public int Top { get; set; }
[JsonProperty("width")]
public int Width { get; set; }
[JsonProperty("height")]
public int Height { get; set; }
[JsonProperty("fill")]
public string Fill { get; set; }
[JsonProperty("stroke")]
public object Stroke { get; set; }
[JsonProperty("strokeWidth")]
public int StrokeWidth { get; set; }
[JsonProperty("strokeDashArray")]
public object StrokeDashArray { get; set; }
[JsonProperty("strokeLineCap")]
public string StrokeLineCap { get; set; }
[JsonProperty("strokeLineJoin")]
public string StrokeLineJoin { get; set; }
[JsonProperty("strokeMiterLimit")]
public int StrokeMiterLimit { get; set; }
[JsonProperty("scaleX")]
public int ScaleX { get; set; }
[JsonProperty("scaleY")]
public int ScaleY { get; set; }
[JsonProperty("angle")]
public int Angle { get; set; }
[JsonProperty("flipX")]
public bool FlipX { get; set; }
[JsonProperty("flipY")]
public bool FlipY { get; set; }
[JsonProperty("opacity")]
public int Opacity { get; set; }
[JsonProperty("shadow")]
public object Shadow { get; set; }
[JsonProperty("visible")]
public bool Visible { get; set; }
[JsonProperty("clipTo")]
public object ClipTo { get; set; }
[JsonProperty("backgroundColor")]
public string BackgroundColor { get; set; }
[JsonProperty("rx")]
public int Rx { get; set; }
[JsonProperty("ry")]
public int Ry { get; set; }
[JsonProperty("x")]
public int X { get; set; }
[JsonProperty("y")]
public int Y { get; set; }
[JsonProperty("label")]
public string Label { get; set; }
}
}
As I try to de-serialize, I get "A first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll [...] Error converting value [...] 'ControlPageDesigner.General.ControlPageResponse'. Path '". I can't seem to find the problem.
ControlPageResponse controlPageRecord = JsonConvert.DeserializeObject<ControlPageResponse>(ControlPage);
ControlPage) is a string variable containing the JSON you included in your post.Typetype in your class ?? why not its full name ? This may be the issue