CSharp · Console
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
public class Program
{
public static void Main()
{
string json = @"
{
""folderPath"": ""D:\\bfi"",
""folderName"": ""ORI"",
""Template"": {
""Width"": ""700"",
""Height"": ""700"",
""Picture"": {
""X"": ""270"",
""Y"": ""0""
},
""Shape"": [
{
""Point"": [
{
""X"": 35,
""Y"": 0
},
{
""X"": 260,
""Y"": 0
},
{
""X"": 260,
""Y"": 250
},
{
""X"": 147.5,
""Y"": 310
},
{
""X"": 35,
""Y"": 250
},
{
""X"": 35,
""Y"": 0
}
],
""Color"": ""13293D""
},
{
""Point"": [
{
""X"": 0,
""Y"": 555
},
{
""X"": 700,
""Y"": 555
},
{
""X"": 700,
""Y"": 700
},
{
""X"": 0,
""Y"": 700
},
{
""X"": 35,
""Y"": 250
},
{
""X"": 0,
""Y"": 555
}
],
""Color"": ""13293D""
}
],
""Word"": [
{
""Text"": ""TEST"",
""Width"": 205,
""Alignment"": ""Center"",
""Color"": ""FAA916"",
""FontFamily"": ""Arial"",
""Size"": 40,
""Style"": ""Regular""
}
]
}
}";
var root = JsonConvert.DeserializeObject<RootObject>(json);
var json2 = JsonConvert.SerializeObject(root, Formatting.Indented);
Console.WriteLine(json2);
}
}
public class RootObject
{
public string FolderPath { get; set; }
public string FolderName { get; set; }
public Template Template { get; set; }
}
public class Template
{
public int Width { get; set; } = 700;
public int Height { get; set; } = 700;
public Picture Picture { get; set; }
public List<Shape> Shape { get; set; }
public List<Word> Word { get; set; }
}
public class Picture
{
public int X { get; set; }
public int Y { get; set; }
}
public class Shape
{
public List<PointF> Point { get; set; }
public string Color { get; set; }
}
public class Word
{
public string Text { get; set; }
public int Width { get; set; }
public HorizontalAlignment Alignment { get; set; } = HorizontalAlignment.Center;
public string Color { get; set; }
public string FontFamily { get; set; }
public int Size { get; set; }
public FontStyle Style { get; set; } = FontStyle.Regular;
}
public struct PointF
{
public float X;
public float Y;
}
public enum HorizontalAlignment { Left, Right, Center }
public enum FontStyle { Regular, Italic, Bold }