public void FromJson(JsonObject item)
{
//通过获取类型,给_ctype赋值
this.NewGetType();
//如果有实体类型,则设置实体类型
if (item.ContainsKey("EntityType"))
{
EntityType = item["EntityType"];
item.Remove("EntityType");
}
foreach (string key in item.Keys)
{
object value = item[key];
Log.Debug("from json name=" + this.Name);
if (key.Equals("id"))
{
Log.Debug("from json id=" + value);
}
//如果是数组,对数组中的每一个对象调用转换过程
if (value is JsonArray)
{
//数组转换成对象列表
ObjectList ol = new ObjectList();
ol.FromJson(value as JsonArray);
SetCollectionProperty(key, ol);
}
else if (value is JsonObject)
{
//JsonObject转换成一般对象
GeneralObject go = new GeneralObject();
go.FromJson(value as JsonObject);
SetPropertyValue(key, go, true);
}
else if (value is JsonPrimitive)
{
this.NewGetType().GetProperty(key).SetValue(this, value as JsonPrimitive, null);
}
else if (value == null)
{
SetPropertyValue(key, null, true);
}
else
{
throw new Exception("类型错误");
}
}
//新加载的对象为未修改
IsModified = false;
}