概要
- https://www.nuget.org/packages/Microsoft.Bcl.AsyncInterfaces/
- https://www.nuget.org/packages/System.Runtime.CompilerServices.Unsafe/
- https://www.nuget.org/packages/System.Text.Encodings.Web
- https://www.nuget.org/packages/System.Text.Json
上記のサイトをそれぞれ開いて
それぞれのページの「Download package」を押して 4 つの .nupkg を入手します
そして、これらのファイルを .zip として展開して
それぞれのフォルダの「lib」フォルダ内の
.dll ファイルを
Unity プロジェクトに追加します
using System.Text.Encodings.Web; using System.Text.Json; using UnityEngine; public sealed class Character { public int Id { get; set; } public string Name { get; set; } } public class Example : MonoBehaviour { private void Start() { var characters = new Character[] { new() { Id = 1, Name = "フシギダネ" }, new() { Id = 2, Name = "フシギソウ" }, new() { Id = 3, Name = "フシギバナ" }, }; var options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, WriteIndented = true, }; var json = JsonSerializer.Serialize( characters, options ); Debug.Log( json ); } }
これで上記のようなコードを記述すると
System.Text.Json を使用できます
検証環境
- Windows 10
- Unity 2021.2.7f1
- Windows IL2CPP ビルド