导入命名空间  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);
    }

 

输出结果

unity   LitJson  用法

 

相关文章:

  • 2022-12-23
  • 2021-07-29
  • 2021-07-04
  • 2021-08-24
  • 2021-10-31
  • 2022-12-23
  • 2021-07-01
  • 2021-07-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2021-12-03
相关资源
相似解决方案