「Unity/Csharp/Json/NewtonJson」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→サンプル) |
(→WebGLで出力したとき) |
||
行39: | 行39: | ||
an error occurred runnning the unity content on this page. | an error occurred runnning the unity content on this page. | ||
see your browser javascript console for more info. | see your browser javascript console for more info. | ||
+ | the error was: | ||
+ | uncaught abort(64) at error | ||
+ | at jsStackTrack(Build.wasm.framework.unityweb:8:15602) | ||
+ | at stackTrace [Object.stackTrace] | ||
</pre> | </pre> | ||
2021年7月5日 (月) 17:03時点における版
NewtonJsonのdllをDL
- https://www.nuget.org/packages/Newtonsoft.Json をDLし、.nupkgを.zipに変更し、解凍。
- lib\netstandard2.0の下のNewtonsoft.Json.dllをPluginsの下に設置
サンプル
using UnityEngine; using UnityEngine.UI; using Newtonsoft.Json; using System; public class SampleScene : MonoBehaviour { [Serializable] public class Item { public string Name; public int Value; } void Start() { GameObject.Find("Button").GetComponent<Button>().onClick.AddListener(OnClick); } void OnClick() { Item itemSource = new Item(); itemSource.Name = "aaa"; itemSource.Value = 111; string json = JsonConvert.SerializeObject(itemSource); Item item = JsonConvert.DeserializeObject<Item>(json); Debug.Log("name=" + item.Name + " value=" + item.Value); GameObject.Find("Text").GetComponent<Text>().text = "name=" + item.Name + " value=" + item.Value; }
ログ:name=aaa value=111
WebGLで出力したとき
以下エラーが出た
an error occurred runnning the unity content on this page. see your browser javascript console for more info. the error was: uncaught abort(64) at error at jsStackTrack(Build.wasm.framework.unityweb:8:15602) at stackTrace [Object.stackTrace]