Commits

Inside Zhou committed 59a8bba

json字符串中的数字默认解析为decimal类型。

Comments (0)

Files changed (5)

Json/ByteArrayConverter.cs

 				return StrToObj(reader.Value.ToString());
 			}
 			else {
-				throw new ArgumentException("Unexpected token parsing date. Expected String, got {0}.".Fmt(CultureInfo.InvariantCulture, reader.TokenType));
+				throw new ArgumentException("Unexpected token parsing byte array. Expected String, got {0}.".Fmt(CultureInfo.InvariantCulture, reader.TokenType));
 			}
 		}
 

Json/DBNullConverter.cs

 				return DBNull.Value;
 			}
 			else {
-				throw new ArgumentException("Unexpected token parsing date. Expected String, got {0}.".Fmt(CultureInfo.InvariantCulture, reader.TokenType));
+				throw new ArgumentException("Unexpected token parsing DBNull. Expected String, got {0}.".Fmt(CultureInfo.InvariantCulture, reader.TokenType));
 			}
 		}
 

Json/DecimalConverter.cs

 				return StrToObj(reader.Value.ToString());
 			}
 			else {
-				throw new ArgumentException("Unexpected token parsing date. Expected String, got {0}.".Fmt(CultureInfo.InvariantCulture, reader.TokenType));
+				throw new ArgumentException("Unexpected token parsing decimal. Expected String, got {0}.".Fmt(CultureInfo.InvariantCulture, reader.TokenType));
 			}
 		}
 

Json/JsonHelper.cs

 		/// 将json字符串反序列化为对象。
 		/// </summary>
 		/// <remarks>
-		/// 如果Json字符串未包含类型细节,则Javascript Object将生成为DyObj,Javascript Array生成为List&lt;dynamic&gt;(dynamic为DyObj)。
+		/// 如果Json字符串未包含类型细节,则Javascript Object将生成为DyObj,Javascript Array生成为List&lt;dynamic&gt;(dynamic为DyObj);不带类型的数字默认被解析为decimal类型
 		/// </remarks>
 		public static object Deserialize(string jsonStr, JsonSerializerSettings settings = null) {
 			if(string.IsNullOrEmpty(jsonStr)) {
 			if(obj.Type == JTokenType.String) {
 				str = obj.Value as string;
 			}
+			else if(obj.Type == JTokenType.Integer || obj.Type == JTokenType.Float) {
+				return Convert.ToDecimal(obj.Value);
+			}
 			else {
 				return obj.Value;
 			}

Json/SimpleDateTimeConverter.cs

 namespace Inside.Util.Json {
 	public class SimpleDateTimeConverter : JsonConverter {
 		internal static bool CanConvert(string str) {
-			var dt = DateTime.Now;
+			DateTime dt;
 			return !string.IsNullOrEmpty(str) && (DateTime.TryParse(str, out dt)) || (str.StartsWith(@"datetime(", StringComparison.Ordinal) && str.EndsWith(@")", StringComparison.Ordinal));
 		}
 
 		internal static DateTime StrToObj(string str) {
-			var dt = DateTime.Now;
+			DateTime dt;
 			if(DateTime.TryParse(str, out dt)) {
-				return DateTime.Parse(str);
+				return dt;
 			}
 
 			if(!CanConvert(str)) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.