|
|
@ -18,7 +18,7 @@ namespace Apewer |
|
|
|
public class Json |
|
|
|
{ |
|
|
|
|
|
|
|
#region 配置。
|
|
|
|
#region 配置。
|
|
|
|
|
|
|
|
[NonSerialized] |
|
|
|
private static bool _throw = false; |
|
|
@ -32,11 +32,11 @@ namespace Apewer |
|
|
|
/// <summary>当存在递归引用时候包含递归项。指定为 True 时递归项为 Null 值,指定为 False 时不包含递归项。默认值:False。</summary>
|
|
|
|
public static bool AllowRecursively { get { return _recursively; } set { _recursively = value; } } |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 构造。
|
|
|
|
#region 构造。
|
|
|
|
|
|
|
|
#region 基础。
|
|
|
|
#region 基础。
|
|
|
|
|
|
|
|
[NonSerialized] |
|
|
|
private JToken _jtoken = null; |
|
|
@ -53,9 +53,9 @@ namespace Apewer |
|
|
|
[NonSerialized] |
|
|
|
private JValue _jvalue = null; |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Reset
|
|
|
|
#region Reset
|
|
|
|
|
|
|
|
/// <summary>重置当前对象为空。</summary>
|
|
|
|
public void Reset() |
|
|
@ -140,7 +140,7 @@ namespace Apewer |
|
|
|
return Reset(dictionary.Origin); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
private void Construct(JToken jtoken = null) |
|
|
|
{ |
|
|
@ -169,9 +169,9 @@ namespace Apewer |
|
|
|
Construct(new JObject()); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 属性。
|
|
|
|
#region 属性。
|
|
|
|
|
|
|
|
/// <summary>用于兼容 SimpleJson 的操作。</summary>
|
|
|
|
public string this[string name] |
|
|
@ -268,9 +268,9 @@ namespace Apewer |
|
|
|
/// <summary>实例无效。</summary>
|
|
|
|
public bool IsNull { get { return _jtoken == null; } } |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Private Get
|
|
|
|
#region Private Get
|
|
|
|
|
|
|
|
private List<Json> PrivateGetProperties { get { return GetProperties(); } } |
|
|
|
|
|
|
@ -280,9 +280,9 @@ namespace Apewer |
|
|
|
|
|
|
|
private List<Json> PrivateGetItems { get { return GetItems(); } } |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Object : Get/Set
|
|
|
|
#region Object : Get/Set
|
|
|
|
|
|
|
|
/// <summary>获取所有类型为 Property 的子项。</summary>
|
|
|
|
public List<Json> GetProperties() |
|
|
@ -681,9 +681,9 @@ namespace Apewer |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Array
|
|
|
|
#region Array
|
|
|
|
|
|
|
|
/// <summary>获取所有类型为 Value 的子项。</summary>
|
|
|
|
public List<Json> GetValues() |
|
|
@ -903,9 +903,9 @@ namespace Apewer |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Property
|
|
|
|
#region Property
|
|
|
|
|
|
|
|
/// <summary>Json 对象实例为空。</summary>
|
|
|
|
public bool IsNone { get { return TokenType == JTokenType.None; } } |
|
|
@ -1077,11 +1077,11 @@ namespace Apewer |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Import / Export
|
|
|
|
#region Import / Export
|
|
|
|
|
|
|
|
#region From Text
|
|
|
|
#region From Text
|
|
|
|
|
|
|
|
/// <summary>从 String 到 Json 的隐式转换。</summary>
|
|
|
|
/// <exception cref="System.Exception"></exception>
|
|
|
@ -1107,9 +1107,9 @@ namespace Apewer |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region From Entity
|
|
|
|
#region From Entity
|
|
|
|
|
|
|
|
/// <summary>解析实现 IList 的对象为 Json 对象,失败时返回 Null。</summary>
|
|
|
|
/// <param name="entity">将要解析的对象。</param>
|
|
|
@ -1277,16 +1277,19 @@ namespace Apewer |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 处理 Type 对象。
|
|
|
|
if (value.GetType().Equals(typeof(Type)) && (previous.Count > 2)) |
|
|
|
if (value != null) |
|
|
|
{ |
|
|
|
value = ((Type)value).FullName; |
|
|
|
} |
|
|
|
// 处理 Type 对象。
|
|
|
|
if (value.GetType().Equals(typeof(Type)) && (previous.Count > 2)) |
|
|
|
{ |
|
|
|
value = ((Type)value).FullName; |
|
|
|
} |
|
|
|
|
|
|
|
// 处理 Assembly 对象。
|
|
|
|
if (value.GetType().Equals(typeof(Assembly)) && (previous.Count > 2)) |
|
|
|
{ |
|
|
|
value = ((Assembly)value).FullName; |
|
|
|
// 处理 Assembly 对象。
|
|
|
|
if (value.GetType().Equals(typeof(Assembly)) && (previous.Count > 2)) |
|
|
|
{ |
|
|
|
value = ((Assembly)value).FullName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (value == null) { json.AddItem(); } |
|
|
@ -1410,9 +1413,9 @@ namespace Apewer |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region To Text
|
|
|
|
#region To Text
|
|
|
|
|
|
|
|
/// <summary>导出文本,可指定缩进。若类型为 String,则导出 String 值,忽略缩进。</summary>
|
|
|
|
internal static string Export(Json json, bool indented) |
|
|
@ -1444,9 +1447,9 @@ namespace Apewer |
|
|
|
return Export(this, indented); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region To Entity
|
|
|
|
#region To Entity
|
|
|
|
|
|
|
|
/// <summary>填充类型实例,失败时返回 NULL 值。</summary>
|
|
|
|
public static T FillObject<T>(Json json, bool ignoreCase = true, string ignoreCharacters = null, bool force = false) where T : class, new() |
|
|
@ -1691,13 +1694,13 @@ namespace Apewer |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Statics
|
|
|
|
#region Statics
|
|
|
|
|
|
|
|
#region 创建实例。
|
|
|
|
#region 创建实例。
|
|
|
|
|
|
|
|
/// <summary>创建新对象。</summary>
|
|
|
|
public static Json NewObject() |
|
|
@ -1861,7 +1864,7 @@ namespace Apewer |
|
|
|
return new Json(new JProperty(name, null)); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
/// <summary>格式化 Json 文本。</summary>
|
|
|
|
public static string Format(string text) |
|
|
@ -1944,7 +1947,7 @@ namespace Apewer |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|