【发布时间】:2017-08-22 02:05:26
【问题描述】:
Json.net 是否有一种现有方法可以使用具体类型作为模板将 json 字符串反序列化为匿名对象(仅具有 json 属性)?
示例
JSON:
{ X: 1, Z: 2 }
型号:
public class Point {
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
}
所需的反序列化输出匿名对象:
new { X=1.0f, Z=1.0f } //Please note that X & Z are typed according to the Point class.
我想做类似的事情:
var @object = serializer.DeserializeAsAnonymous<Point>(json);
为什么?我想检测模型的哪些属性要使用两边的反射来更新(模型和提供的反序列化 json)。
【问题讨论】:
标签: c# json.net deserialization json-deserialization