导入命名空间 using LitJson;
代码如下
private void Start()
{
//定义json字符串
string json = "{"key1"" + ":" + ""value1"" + "," + ""key2"" + ":" + ""value2"" + "}";
Debug.LogError(json);
//将json字符串装换成 JsonData
JsonData data = JsonMapper.ToObject(json);
//获取json字符串的值
Debug.LogError(data["key1"]);
//获取Json数据
data["key3"] = "value3";
//添加新数据
Debug.LogError(data["key3"]);
//将JsonData转换成json字符串
string jsonStr = JsonMapper.ToJson(data);
Debug.LogError(jsonStr);
}
输出结果