com.unity.nuget.newtonsoft-json
Utilities.cs <- JsonConvert 클래스 래핑 직접 씀
using System.IO;
using Newtonsoft.Json;
public static class Json {
public static string ReadJson(string path, string fileName) {
return File.ReadAllText(path + fileName);
}
public static void WriteJson(string jsonString, string fileName) {
File.WriteAllText("Resources/" + fileName, jsonString);
}
public static string ToJson<T>(T data) {
return JsonConvert.SerializeObject(data);
}
public static T FromJson<T>(string jsonString) {
return JsonConvert.DeserializeObject<T>(jsonString);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VideoStatements : MonoBehaviour {
private Dictionary<string, PlaysData> plays = new();
private List<InvoicesData> invoices = new();
void Start() {
string playsJson = Json.ReadJson("Resources/", "plays.json");
plays = Json.FromJson<Dictionary<string, PlaysData>>(playsJson);
string invoicesJson = Json.ReadJson("Resources/", "invoices.json");
invoices = Json.FromJson<List<InvoicesData>>(invoicesJson);
}
}
public class PlaysData {
public string name;
public string type;
}
public class InvoicesData {
public string customer;
public List<Performance> performances;
public class Performance {
public string playID;
public int audience;
}
}