public class Rectangle
{
public int id { get; set; }
public TextureRect textureRect { get; set; }
public static List<Rectangle> ParseFromJSON(string json)
{
return JsonConvert.DeserializeObject<List<Rectangle>>(json);
}
}
public class TextureRect
{
public int x { get; set; }
public int y { get; set; }
public int width { get; set; }
public int height { get; set; }
}
Imports will be :
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
Thanks for the answer but could you elaborate a bit more on why I should switch to System.Text.Json if I’m using .Net core 3. I couldn’t find any resources online on the reason for that.
If using json.net you can create your own json converters where you tell it when it finds “rectangle” to check if it matches this type. If matches can tell it to create a rectangle from json to object or object to json (text).