相关链接
声明命名空间
using LitJson;
ps: 直接将 .dll
文件拖入 Unity 的 Assets 目录中便可以使用了
转换
-
实例转换为JSON
public class Pet { public string name; public int age; string color; public void Bark () { /***/} }
using LitJson; ... JsonMapper.toJson(new Pet()); // => string: "{ 'name': null, 'age': 0 }"
PS: 实例方法和未公开的属性不会被转化
-
嵌套实例对象转换为JSON
public class PetColor { public int r; public int g; public int b; } public class Pet { public string name; public int age; public PetColor color; }