ソースコード
using LitJson; using System.Text; public static class JsonUtils { public static string ToJson<T>( T obj ) { var builder = new StringBuilder(); var writer = new JsonWriter( builder ) { PrettyPrint = true }; JsonMapper.ToJson( obj, writer ); return builder.ToString(); } }
使い方
public class Player { public int mId ; public string mName; } ... var player = new Player(); var json = JsonUtils.ToJson( player ); Debug.Log( json );
出力結果
{ "mId" : 0, "mName" : null }