在Unity中序列化和反序列化Json和Json Array
原文的地址:http://stackoverflow.com/questions/36239705/serialize-and-deserialize-json-and-json-array-in-unity
本文仅作学习分享。
------------------------------------------------------------------------------------------------------------------------
因为Unity版本号5.6,所以使用 [Serializable],就改为了[System.Serializable]
把数组 转换 为 JSON 数据,才能进行存储。
JsonUtility.ToJson(playerInstance, true);
[System.Serializable]
public class Player
{
public string playerId;
public string playerLoc;
public string playerNick;
}
再把从.json 里面的文件读取,JSON数据 转换 为 player 数组,就可以正常输出。

这篇博客介绍了如何在Unity 5.6版本中使用内置的[System.Serializable]进行JSON数组的序列化和反序列化。通过创建Player类,将玩家数据转换为JSON字符串并存储,然后从JSON文件中读取数据并恢复为Player数组。示例代码包括TestJSON和JsonHelper两个类,用于实现这些功能。
最低0.47元/天 解锁文章
2553

被折叠的 条评论
为什么被折叠?



