Unity3D之Json序列化
//Unity3D之Json序列化
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using LitJson;
using System.Text;
public class Test : MonoBehaviour
{
class User
{
public string id;
public string pwd;
public Dictionary<string, string> map = new Dictionary<string, string>();
}
void Start()
{
User u = new User();
u.id = "1";
u.pwd = "12345678";
u.map["test"] = "xxxxxxxxmap test";
string json = JsonMapper.ToJson(u);
User u1 = JsonMapper.ToObject<User>(json);
Debug.Log(json);
Debug.Log(u1.id + " " + u1.map["test"]);
}
}
//打印
//json工具
LitJson,百度搜一下,有很多资料。