【发布时间】:2019-02-08 23:47:32
【问题描述】:
我一直在为我的 Unity 项目寻找更好的 json 库。我需要使用除属性名称之外的其他名称进行序列化,反序列化包含任意用户定义内容的字典并忽略序列化中的空字段。我已将 Json.NET v12.0.1 的 .dll (net20) 添加到我的 Unity 项目中,它似乎在我的(有限)测试中运行良好。
public class Foo
{
[JsonProperty("baz", NullValueHandling = NullValueHandling.Ignore)]
public Bar Baz{ get; set; }
[JsonProperty("quux", NullValueHandling = NullValueHandling.Ignore)]
public Qux Quux{ get; set; }
}
public class Corge: Dictionary<string, JObject>
{
//whatever the user wants to send will come back from the REST call
}
public void OnResponse(string responseJson)
{
var corge = JsonConvert.DeserializeObject<Corge>(responseJson);
var name = corge["name"].ToString();
}
在我完全重构我的项目之前,在 Unity 中使用 Json.NET 并发布到不同平台会有任何限制吗?使用dynamic 会比扩展Dictionary 更好吗?
【问题讨论】: