P
P
Pragma Games2021-09-22 12:29:39
C++ / C#
Pragma Games, 2021-09-22 12:29:39

How to serialize complex object to JSON?

I want to store information about levels in separate files, and I can't figure out how to serialize such an object. As you understand the main trouble in the sheet (can be replaced with an array).
614af739334fa931417347.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-09-22
@PragmaGames

How do you understand the main trouble in the sheet (can be replaced with an array)

I don't understand what the problem is.
614b094b4ee1a044179313.png
Both System.Text.Json and Newtonsoft.Json can serialize sheets out of the box.
The problem can only arise when using fields, instead of properties - then you just need to specify in the options that you need to include fields.
var obj = new TestObject { SomeField = "asd" };
JsonSerializer.Serialize(obj, new JsonSerializerOptions() { IncludeFields = true });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question