Advertisement
Guest User

fastJSON diff

a guest
Apr 15th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 25.48 KB | None | 0 0
  1.  Consoletest/Program.cs         |  31 ++--
  2.  Consoletest/consoletest.csproj |   1 -
  3.  Consoletest/dataobjects.cs     |   4 +
  4.  fastJSON/JSON.cs               | 338 ++++++++++++++++++++++++++---------------
  5.  fastJSON/JsonParser.cs         |  11 +-
  6.  fastJSON/JsonSerializer.cs     |  28 ++--
  7.  fastJSON/fastJSON.csproj       |   4 +-
  8.  7 files changed, 261 insertions(+), 156 deletions(-)
  9.  
  10. diff --git a/Consoletest/Program.cs b/Consoletest/Program.cs
  11. index 1911e21..68a8b5e 100644
  12. --- a/Consoletest/Program.cs
  13. +++ b/Consoletest/Program.cs
  14. @@ -2,6 +2,7 @@
  15.  using System.Collections;
  16.  using System.Collections.Generic;
  17.  using System.Data;
  18. +using System.Diagnostics;
  19.  using System.IO;
  20.  using System.Reflection;
  21.  using System.Runtime.Serialization.Formatters.Binary;
  22. @@ -171,19 +172,21 @@ namespace consoletest
  23.              Console.WriteLine();
  24.              Console.Write("fastjson deserialize");
  25.              colclass c = CreateObject();
  26. +           var stopwatch = new Stopwatch();
  27.              for (int pp = 0; pp < tcount; pp++)
  28.              {
  29. -                DateTime st = DateTime.Now;
  30.                  colclass deserializedStore;
  31.                  string jsonText = null;
  32.  
  33. +               stopwatch.Restart();
  34.                  jsonText = fastJSON.JSON.Instance.ToJSON(c);
  35.                  //Console.WriteLine(" size = " + jsonText.Length);
  36.                  for (int i = 0; i < count; i++)
  37.                  {
  38.                      deserializedStore = (colclass)fastJSON.JSON.Instance.ToObject(jsonText);
  39.                  }
  40. -                Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
  41. +               stopwatch.Stop();
  42. +               Console.Write("\t" + stopwatch.ElapsedMilliseconds);
  43.              }
  44.          }
  45.  
  46. @@ -192,15 +195,17 @@ namespace consoletest
  47.              Console.WriteLine();
  48.              Console.Write("fastjson serialize");
  49.              colclass c = CreateObject();
  50. +           var stopwatch = new Stopwatch();
  51.              for (int pp = 0; pp < tcount; pp++)
  52.              {
  53. -                DateTime st = DateTime.Now;
  54.                  string jsonText = null;
  55. +               stopwatch.Restart();
  56.                  for (int i = 0; i < count; i++)
  57.                  {
  58.                      jsonText = fastJSON.JSON.Instance.ToJSON(c);
  59.                  }
  60. -                Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
  61. +               stopwatch.Stop();
  62. +               Console.Write("\t" + stopwatch.ElapsedMilliseconds);
  63.              }
  64.          }
  65.  
  66. @@ -209,20 +214,24 @@ namespace consoletest
  67.              Console.WriteLine();
  68.              Console.Write("bin deserialize");
  69.              colclass c = CreateObject();
  70. +           var stopwatch = new Stopwatch();
  71.              for (int pp = 0; pp < tcount; pp++)
  72.              {
  73. -                DateTime st = DateTime.Now;
  74.                  BinaryFormatter bf = new BinaryFormatter();
  75.                  MemoryStream ms = new MemoryStream();
  76. +               colclass deserializedStore = null;
  77. +               stopwatch.Restart();
  78.                  bf.Serialize(ms, c);
  79. -                colclass deserializedStore = null;
  80.                  //Console.WriteLine(" size = " +ms.Length);
  81.                  for (int i = 0; i < count; i++)
  82.                  {
  83. +                   stopwatch.Stop(); // we stop then resume the stopwatch here so we don't factor in Seek()'s execution
  84.                      ms.Seek(0L, SeekOrigin.Begin);
  85. +                   stopwatch.Start();
  86.                      deserializedStore = (colclass)bf.Deserialize(ms);
  87.                  }
  88. -                Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
  89. +               stopwatch.Stop();
  90. +               Console.Write("\t" + stopwatch.ElapsedMilliseconds);
  91.              }
  92.          }
  93.  
  94. @@ -230,17 +239,21 @@ namespace consoletest
  95.          {
  96.              Console.Write("\r\nbin serialize");
  97.              colclass c = CreateObject();
  98. +           var stopwatch = new Stopwatch();
  99.              for (int pp = 0; pp < tcount; pp++)
  100.              {
  101. -                DateTime st = DateTime.Now;
  102.                  BinaryFormatter bf = new BinaryFormatter();
  103.                  MemoryStream ms = new MemoryStream();
  104. +               stopwatch.Restart();
  105.                  for (int i = 0; i < count; i++)
  106.                  {
  107. +                   stopwatch.Stop(); // we stop then resume the stop watch here so we don't factor in the MemoryStream()'s execution
  108.                      ms = new MemoryStream();
  109. +                   stopwatch.Start();
  110.                      bf.Serialize(ms, c);
  111.                  }
  112. -                Console.Write("\t" + DateTime.Now.Subtract(st).TotalMilliseconds);
  113. +               stopwatch.Stop();
  114. +               Console.Write("\t" + stopwatch.ElapsedMilliseconds);
  115.              }
  116.          }
  117.  
  118. diff --git a/Consoletest/consoletest.csproj b/Consoletest/consoletest.csproj
  119. index 1af547c..9652f6f 100644
  120. --- a/Consoletest/consoletest.csproj
  121. +++ b/Consoletest/consoletest.csproj
  122. @@ -59,7 +59,6 @@
  123.      <Reference Include="System" />
  124.      <Reference Include="System.Data" />
  125.      <Reference Include="System.Drawing" />
  126. -    <Reference Include="System.Windows.Forms" />
  127.      <Reference Include="System.Xml" />
  128.    </ItemGroup>
  129.    <ItemGroup>
  130. diff --git a/Consoletest/dataobjects.cs b/Consoletest/dataobjects.cs
  131. index 8a77c3a..2631a4c 100644
  132. --- a/Consoletest/dataobjects.cs
  133. +++ b/Consoletest/dataobjects.cs
  134. @@ -8,12 +8,14 @@ namespace consoletest
  135.  
  136.     #region [   data objects   ]
  137.  
  138. +   [Serializable]
  139.     public class baseclass
  140.     {
  141.         public string Name { get; set; }
  142.         public string Code { get; set; }
  143.     }
  144.  
  145. +   [Serializable]
  146.     public class class1 : baseclass
  147.     {
  148.         public class1() { }
  149. @@ -26,6 +28,7 @@ namespace consoletest
  150.         public Guid guid { get; set; }
  151.     }
  152.  
  153. +   [Serializable]
  154.     public class class2 : baseclass
  155.     {
  156.         public class2() { }
  157. @@ -44,6 +47,7 @@ namespace consoletest
  158.         Female
  159.     }
  160.  
  161. +   [Serializable]
  162.     public class colclass
  163.     {
  164.         public colclass()
  165. diff --git a/fastJSON/JSON.cs b/fastJSON/JSON.cs
  166. index 452a822..81b1260 100644
  167. --- a/fastJSON/JSON.cs
  168. +++ b/fastJSON/JSON.cs
  169. @@ -68,6 +68,7 @@ namespace fastJSON
  170.  
  171.      public sealed class JSON
  172.      {
  173. +       //static JSON() { Console.WriteLine("myPropInfo: {0}", System.Runtime.InteropServices.Marshal.SizeOf(typeof(myPropInfo)).ToString("X8")); }
  174.          //public readonly static JSON Instance = new JSON();
  175.          [ThreadStatic]
  176.          private static JSON _instance;
  177. @@ -229,39 +230,55 @@ namespace fastJSON
  178.  
  179.          #region [   JSON specific reflection   ]
  180.  
  181. +       private enum myPropInfoType
  182. +       {
  183. +           Int,
  184. +           Long,
  185. +           String,
  186. +           Bool,
  187. +           DateTime,
  188. +           Enum,
  189. +           Guid,
  190. +
  191. +           Array,
  192. +           ByteArray,
  193. +           Dictionary,
  194. +           StringDictionary,
  195. +#if !SILVERLIGHT
  196. +           Hashtable,
  197. +           DataSet,
  198. +           DataTable,
  199. +#endif
  200. +#if CUSTOMTYPE
  201. +           Custom,
  202. +#endif
  203. +
  204. +           Unknown,
  205. +       };
  206. +       [Flags]
  207. +       private enum myPropInfoFlags
  208. +       {
  209. +           Filled = 1<<0,
  210. +           CanWrite = 1<<1,
  211. +           Class = 1<<2,
  212. +           ValueType = 1<<3,
  213. +           GenericType = 1<<4,
  214. +       };
  215.          private struct myPropInfo
  216.          {
  217. -            public bool filled;
  218.              public Type pt;
  219.              public Type bt;
  220.              public Type changeType;
  221. -            public bool isDictionary;
  222. -            public bool isValueType;
  223. -            public bool isGenericType;
  224. -            public bool isArray;
  225. -            public bool isByteArray;
  226. -            public bool isGuid;
  227. -#if !SILVERLIGHT
  228. -            public bool isDataSet;
  229. -            public bool isDataTable;
  230. -            public bool isHashtable;
  231. -#endif
  232. -            public Reflection.GenericSetter setter;
  233. -            public bool isEnum;
  234. -            public bool isDateTime;
  235. -            public Type[] GenericTypes;
  236. -            public bool isInt;
  237. -            public bool isLong;
  238. -            public bool isString;
  239. -            public bool isBool;
  240. -            public bool isClass;
  241. -            public Reflection.GenericGetter getter;
  242. -            public bool isStringDictionary;
  243. -            public string Name;
  244. -#if CUSTOMTYPE
  245. -            public bool isCustomType;
  246. -#endif
  247. -            public bool CanWrite;
  248. +           public Reflection.GenericSetter setter;
  249. +           public Reflection.GenericGetter getter;
  250. +           public Type[] GenericTypes;
  251. +           public string Name;
  252. +           public myPropInfoType Type;
  253. +           public myPropInfoFlags Flags;
  254. +
  255. +           public bool IsClass { get { return (Flags & myPropInfoFlags.Class) != 0; } }
  256. +           public bool IsValueType { get { return (Flags & myPropInfoFlags.ValueType) != 0; } }
  257. +           public bool IsGenericType { get { return (Flags & myPropInfoFlags.GenericType) != 0; } }
  258.          }
  259.  
  260.          SafeDictionary<string, SafeDictionary<string, myPropInfo>> _propertycache = new SafeDictionary<string, SafeDictionary<string, myPropInfo>>();
  261. @@ -279,7 +296,7 @@ namespace fastJSON
  262.                  foreach (PropertyInfo p in pr)
  263.                  {
  264.                      myPropInfo d = CreateMyProp(p.PropertyType, p.Name);
  265. -                    d.CanWrite = p.CanWrite;
  266. +                    d.Flags |= myPropInfoFlags.CanWrite;
  267.                      d.setter = Reflection.CreateSetMethod(type, p);
  268.                      d.getter = Reflection.CreateGetMethod(type, p);
  269.                      sd.Add(p.Name, d);
  270. @@ -301,44 +318,55 @@ namespace fastJSON
  271.          private myPropInfo CreateMyProp(Type t, string name)
  272.          {
  273.              myPropInfo d = new myPropInfo();
  274. -            d.filled = true;
  275. -            d.CanWrite = true;
  276. -            d.pt = t;
  277. -            d.Name = name;
  278. -            d.isDictionary = t.Name.Contains("Dictionary");
  279. -            if (d.isDictionary)
  280. -                d.GenericTypes = t.GetGenericArguments();
  281. -            d.isValueType = t.IsValueType;
  282. -            d.isGenericType = t.IsGenericType;
  283. -            d.isArray = t.IsArray;
  284. -            if (d.isArray)
  285. -                d.bt = t.GetElementType();
  286. -            if (d.isGenericType)
  287. -                d.bt = t.GetGenericArguments()[0];
  288. -            d.isByteArray = t == typeof(byte[]);
  289. -            d.isGuid = (t == typeof(Guid) || t == typeof(Guid?));
  290. +           myPropInfoType d_type = myPropInfoType.Unknown;
  291. +           myPropInfoFlags d_flags = myPropInfoFlags.Filled | myPropInfoFlags.CanWrite;
  292. +
  293. +                if (t == typeof(int) || t == typeof(int?))             d_type = myPropInfoType.Int;
  294. +           else if (t == typeof(long) || t == typeof(long?))           d_type = myPropInfoType.Long;
  295. +           else if (t == typeof(string))                               d_type = myPropInfoType.String;
  296. +           else if (t == typeof(bool) || t == typeof(bool?))           d_type = myPropInfoType.Bool;
  297. +           else if (t == typeof(DateTime) || t == typeof(DateTime?))   d_type = myPropInfoType.DateTime;
  298. +           else if (t.IsEnum)                                          d_type = myPropInfoType.Enum;
  299. +           else if (t == typeof(Guid) || t == typeof(Guid?))           d_type = myPropInfoType.Guid;
  300. +           else if (t.IsArray)
  301. +           {
  302. +               d.bt = t.GetElementType();
  303. +               if (t == typeof(byte[]))
  304. +                   d_type = myPropInfoType.ByteArray;
  305. +               else
  306. +                   d_type = myPropInfoType.Array;
  307. +           }
  308. +           else if (t.Name.Contains("Dictionary"))
  309. +           {
  310. +               d.GenericTypes = t.GetGenericArguments();
  311. +               if(d.GenericTypes.Length > 0 && d.GenericTypes[0] == typeof(string))
  312. +                   d_type = myPropInfoType.StringDictionary;
  313. +               else
  314. +                   d_type = myPropInfoType.Dictionary;
  315. +           }
  316.  #if !SILVERLIGHT
  317. -            d.isHashtable = t == typeof(Hashtable);
  318. -            d.isDataSet = t == typeof(DataSet);
  319. -            d.isDataTable = t == typeof(DataTable);
  320. +           else if (t == typeof(Hashtable))                            d_type = myPropInfoType.Hashtable;
  321. +           else if (t == typeof(DataSet))                              d_type = myPropInfoType.DataSet;
  322. +           else if (t == typeof(DataTable))                            d_type = myPropInfoType.DataTable;
  323. +#endif
  324. +#if CUSTOMTYPE
  325. +            else if (IsTypeRegistered(t))                              d_type = myPropInfoType.Custom;
  326.  #endif
  327.  
  328. -            d.changeType = GetChangeType(t);
  329. -            d.isEnum = t.IsEnum;
  330. -            d.isDateTime = t == typeof(DateTime) || t == typeof(DateTime?);
  331. -            d.isInt = t == typeof(int) || t == typeof(int?);
  332. -            d.isLong = t == typeof(long) || t == typeof(long?);
  333. -            d.isString = t == typeof(string);
  334. -            d.isBool = t == typeof(bool) || t == typeof(bool?);
  335. -            d.isClass = t.IsClass;
  336. +           if (t.IsClass)          d_flags |= myPropInfoFlags.Class;
  337. +           if (t.IsValueType)      d_flags |= myPropInfoFlags.ValueType;
  338. +           if (t.IsGenericType)
  339. +           {
  340. +               d_flags |= myPropInfoFlags.GenericType;
  341. +               d.bt = t.GetGenericArguments()[0];
  342. +           }
  343.  
  344. -            if (d.isDictionary && d.GenericTypes.Length > 0 && d.GenericTypes[0] == typeof(string))
  345. -                d.isStringDictionary = true;
  346. +            d.pt = t;
  347. +            d.Name = name;
  348. +            d.changeType = GetChangeType(t);
  349. +           d.Type = d_type;
  350. +           d.Flags = d_flags;
  351.  
  352. -#if CUSTOMTYPE
  353. -            if (IsTypeRegistered(t))
  354. -                d.isCustomType = true;
  355. -#endif
  356.              return d;
  357.          }
  358.  
  359. @@ -469,74 +497,59 @@ namespace fastJSON
  360.                  myPropInfo pi;
  361.                  if (props.TryGetValue(name, out pi) == false)
  362.                      continue;
  363. -                if (pi.filled && pi.CanWrite)
  364. +                if ((pi.Flags & (myPropInfoFlags.Filled|myPropInfoFlags.CanWrite)) != 0)
  365.                  {
  366.                      object v = d[name];
  367.  
  368.                      if (v != null)
  369.                      {
  370. -                        object oset = null;
  371. -
  372. -                        if (pi.isInt)
  373. -                            oset = (int)((long)v);
  374. -#if CUSTOMTYPE
  375. -                        else if (pi.isCustomType)
  376. -                            oset = CreateCustom((string)v, pi.pt);
  377. -#endif
  378. -                        else if (pi.isLong)
  379. -                            oset = (long)v;
  380. -
  381. -                        else if (pi.isString)
  382. -                            oset = (string)v;
  383. -
  384. -                        else if (pi.isBool)
  385. -                            oset = (bool)v;
  386. -
  387. -                        else if (pi.isGenericType && pi.isValueType == false && pi.isDictionary == false && v is List<object>)
  388. -                            oset = CreateGenericList((List<object>)v, pi.pt, pi.bt, globaltypes);
  389. -
  390. -                        else if (pi.isByteArray)
  391. -                            oset = Convert.FromBase64String((string)v);
  392. -
  393. -                        else if (pi.isArray && pi.isValueType == false)
  394. -                            oset = CreateArray((List<object>)v, pi.pt, pi.bt, globaltypes);
  395. -
  396. -                        else if (pi.isGuid)
  397. -                            oset = CreateGuid((string)v);
  398. +                       object oset = null;
  399. +
  400. +                       switch (pi.Type)
  401. +                       {
  402. +                           case myPropInfoType.Int: oset = (int)((long)v); break;
  403. +                           case myPropInfoType.Long: oset = (long)v; break;
  404. +                           case myPropInfoType.String: oset = (string)v; break;
  405. +                           case myPropInfoType.Bool: oset = (bool)v; break;
  406. +                           case myPropInfoType.DateTime: oset = CreateDateTime((string)v); break;
  407. +                           case myPropInfoType.Enum: oset = CreateEnum(pi.pt, (string)v); break;
  408. +                           case myPropInfoType.Guid: oset = CreateGuid((string)v); break;
  409. +
  410. +                           case myPropInfoType.Array:
  411. +                               if(!pi.IsValueType)
  412. +                                   oset = CreateArray((List<object>)v, pi.pt, pi.bt, globaltypes);
  413. +                               // what about 'else'?
  414. +                               break;
  415. +                           case myPropInfoType.ByteArray: oset = Convert.FromBase64String((string)v); break;
  416.  #if !SILVERLIGHT
  417. -                        else if (pi.isDataSet)
  418. -                            oset = CreateDataset((Dictionary<string, object>)v, globaltypes);
  419. -
  420. -                        else if (pi.isDataTable)
  421. -                            oset = this.CreateDataTable((Dictionary<string, object>)v, globaltypes);
  422. +                           case myPropInfoType.DataSet: oset = CreateDataset((Dictionary<string, object>)v, globaltypes); break;
  423. +                           case myPropInfoType.DataTable: oset = this.CreateDataTable((Dictionary<string, object>)v, globaltypes); break;
  424. +                           case myPropInfoType.Hashtable: // same case as Dictionary
  425.  #endif
  426. -
  427. -                        else if (pi.isStringDictionary)
  428. -                            oset = CreateStringKeyDictionary((Dictionary<string, object>)v, pi.pt, pi.GenericTypes, globaltypes);
  429. -#if !SILVERLIGHT
  430. -                        else if (pi.isDictionary || pi.isHashtable)
  431. -#else
  432. -                        else if (pi.isDictionary)
  433. +                           case myPropInfoType.Dictionary: oset = CreateDictionary((List<object>)v, pi.pt, pi.GenericTypes, globaltypes); break;
  434. +                           case myPropInfoType.StringDictionary: oset = CreateStringKeyDictionary((Dictionary<string, object>)v, pi.pt, pi.GenericTypes, globaltypes); break;
  435. +#if CUSTOMTYPE
  436. +                           case myPropInfoType.Custom: oset = CreateCustom((string)v, pi.pt); break;
  437.  #endif
  438. -                            oset = CreateDictionary((List<object>)v, pi.pt, pi.GenericTypes, globaltypes);
  439. -
  440. -                        else if (pi.isEnum)
  441. -                            oset = CreateEnum(pi.pt, (string)v);
  442. -
  443. -                        else if (pi.isDateTime)
  444. -                            oset = CreateDateTime((string)v);
  445. +                           default:
  446. +                               {
  447. +                                   if (pi.IsGenericType && pi.IsValueType == false && v is List<object>)
  448. +                                       oset = CreateGenericList((List<object>)v, pi.pt, pi.bt, globaltypes);
  449.  
  450. -                        else if (pi.isClass && v is Dictionary<string, object>)
  451. -                            oset = ParseDictionary((Dictionary<string, object>)v, globaltypes, pi.pt, pi.getter(o));
  452. +                                   else if (pi.IsClass && v is Dictionary<string, object>)
  453. +                                       oset = ParseDictionary((Dictionary<string, object>)v, globaltypes, pi.pt, pi.getter(o));
  454.  
  455. -                        else if (pi.isValueType)
  456. -                            oset = ChangeType(v, pi.changeType);
  457. +                                   else if (v is List<object>)
  458. +                                       oset = CreateArray((List<object>)v, pi.pt, typeof(object), globaltypes);
  459.  
  460. -                        else if (v is List<object>)
  461. -                            oset = CreateArray((List<object>)v, pi.pt, typeof(object), globaltypes);
  462. +                                   else if (pi.IsValueType)
  463. +                                       oset = ChangeType(v, pi.changeType);
  464.  
  465. -                        else
  466. -                            oset = v;
  467. +                                   else
  468. +                                       oset = v;
  469. +                               }
  470. +                               break;
  471. +                       }
  472.  
  473.                          o = pi.setter(o, oset);
  474.                      }
  475. @@ -566,6 +579,72 @@ namespace fastJSON
  476.              }
  477.          }
  478.  
  479. +       static int CreateInteger(out int num, string s, int index, int count)
  480. +       {
  481. +           num = 0;
  482. +           bool neg = false;
  483. +           for (int x = 0; x < count; x++, index++)
  484. +           {
  485. +               char cc = s[index];
  486. +
  487. +               if (cc == '-')
  488. +                   neg = true;
  489. +               else if (cc == '+')
  490. +                   neg = false;
  491. +               else
  492. +               {
  493. +                   num *= 10;
  494. +                   num += (int)(cc - '0');
  495. +               }
  496. +           }
  497. +           if(neg) num = -num;
  498. +
  499. +           return num;
  500. +       }
  501. +       static long CreateInteger(out long num, string s, int index, int count)
  502. +       {
  503. +           num = 0;
  504. +           bool neg = false;
  505. +           for (int x = 0; x < count; x++, index++)
  506. +           {
  507. +               char cc = s[index];
  508. +
  509. +               if (cc == '-')
  510. +                   neg = true;
  511. +               else if (cc == '+')
  512. +                   neg = false;
  513. +               else
  514. +               {
  515. +                   num *= 10;
  516. +                   num += (int)(cc - '0');
  517. +               }
  518. +           }
  519. +           if (neg) num = -num;
  520. +
  521. +           return num;
  522. +       }
  523. +       internal static long CreateInteger(out long num, char[] s, int index, int count)
  524. +       {
  525. +           num = 0;
  526. +           bool neg = false;
  527. +           for (int x = 0; x < count; x++, index++)
  528. +           {
  529. +               char cc = s[index];
  530. +
  531. +               if (cc == '-')
  532. +                   neg = true;
  533. +               else if (cc == '+')
  534. +                   neg = false;
  535. +               else
  536. +               {
  537. +                   num *= 10;
  538. +                   num += (int)(cc - '0');
  539. +               }
  540. +           }
  541. +           if (neg) num = -num;
  542. +
  543. +           return num;
  544. +       }
  545.          private long CreateLong(string s)
  546.          {
  547.              long num = 0;
  548. @@ -609,14 +688,21 @@ namespace fastJSON
  549.              bool utc = false;
  550.              //                   0123456789012345678
  551.              // datetime format = yyyy-MM-dd HH:mm:ss
  552. -            int year = (int)CreateLong(value.Substring(0, 4));
  553. -            int month = (int)CreateLong(value.Substring(5, 2));
  554. -            int day = (int)CreateLong(value.Substring(8, 2));
  555. -            int hour = (int)CreateLong(value.Substring(11, 2));
  556. -            int min = (int)CreateLong(value.Substring(14, 2));
  557. -            int sec = (int)CreateLong(value.Substring(17, 2));
  558. -
  559. -            if (value.EndsWith("Z"))
  560. +            int year;// = (int)CreateLong(value.Substring(0, 4));
  561. +            int month;// = (int)CreateLong(value.Substring(5, 2));
  562. +            int day;// = (int)CreateLong(value.Substring(8, 2));
  563. +            int hour;// = (int)CreateLong(value.Substring(11, 2));
  564. +            int min;// = (int)CreateLong(value.Substring(14, 2));
  565. +            int sec;// = (int)CreateLong(value.Substring(17, 2));
  566. +           CreateInteger(out year, value, 0, 4);
  567. +           CreateInteger(out month, value, 5, 2);
  568. +           CreateInteger(out day, value, 8, 2);
  569. +           CreateInteger(out hour, value, 11, 2);
  570. +           CreateInteger(out min, value, 14, 2);
  571. +           CreateInteger(out sec, value, 17, 2);
  572. +
  573. +            //if (value.EndsWith("Z"))
  574. +           if (value[value.Length-1] == 'Z')
  575.                  utc = true;
  576.  
  577.              if (_params.UseUTCDateTime == false && utc == false)
  578. diff --git a/fastJSON/JsonParser.cs b/fastJSON/JsonParser.cs
  579. index 3c2abdd..929ab73 100644
  580. --- a/fastJSON/JsonParser.cs
  581. +++ b/fastJSON/JsonParser.cs
  582. @@ -305,10 +305,13 @@ namespace fastJSON
  583.                  break;
  584.              } while (true);
  585.  
  586. -            string s = new string(json, startIndex, index - startIndex);
  587. -            if (dec)
  588. -                return double.Parse(s,NumberFormatInfo.InvariantInfo);
  589. -            return CreateLong(s);
  590. +           if (dec)
  591. +           {
  592. +               string s = new string(json, startIndex, index - startIndex);
  593. +               return double.Parse(s, NumberFormatInfo.InvariantInfo);
  594. +           }
  595. +           long num;
  596. +           return JSON.CreateInteger(out num, json, startIndex, index - startIndex);
  597.          }
  598.  
  599.          private Token LookAhead()
  600. diff --git a/fastJSON/JsonSerializer.cs b/fastJSON/JsonSerializer.cs
  601. index 50c8c9d..a3611c5 100644
  602. --- a/fastJSON/JsonSerializer.cs
  603. +++ b/fastJSON/JsonSerializer.cs
  604. @@ -40,11 +40,11 @@ namespace fastJSON
  605.                  {
  606.                      if (pendingSeparator) sb.Append(',');
  607.                      pendingSeparator = true;
  608. -                    sb.Append("\"");
  609. +                    sb.Append('\"');
  610.                      sb.Append(kv.Key);
  611.                      sb.Append("\":\"");
  612.                      sb.Append(kv.Value);
  613. -                    sb.Append("\"");
  614. +                    sb.Append('\"');
  615.                  }
  616.                  sb.Append("},");
  617.                  sb.Append(_output.ToString());
  618. @@ -150,23 +150,23 @@ namespace fastJSON
  619.              if (_params.UseUTCDateTime)
  620.                  dt = dateTime.ToUniversalTime();
  621.  
  622. -            _output.Append("\"");
  623. +            _output.Append('\"');
  624.              _output.Append(dt.Year.ToString("0000", NumberFormatInfo.InvariantInfo));
  625. -            _output.Append("-");
  626. +            _output.Append('-');
  627.              _output.Append(dt.Month.ToString("00", NumberFormatInfo.InvariantInfo));
  628. -            _output.Append("-");
  629. +            _output.Append('-');
  630.              _output.Append(dt.Day.ToString("00", NumberFormatInfo.InvariantInfo));
  631. -            _output.Append(" ");
  632. +            _output.Append(' ');
  633.              _output.Append(dt.Hour.ToString("00", NumberFormatInfo.InvariantInfo));
  634. -            _output.Append(":");
  635. +            _output.Append(':');
  636.              _output.Append(dt.Minute.ToString("00", NumberFormatInfo.InvariantInfo));
  637. -            _output.Append(":");
  638. +            _output.Append(':');
  639.              _output.Append(dt.Second.ToString("00", NumberFormatInfo.InvariantInfo));
  640.  
  641.              if (_params.UseUTCDateTime)
  642. -                _output.Append("Z");
  643. +                _output.Append('Z');
  644.  
  645. -            _output.Append("\"");
  646. +            _output.Append('\"');
  647.          }
  648.  
  649.  #if !SILVERLIGHT
  650. @@ -231,7 +231,7 @@ namespace fastJSON
  651.              bool tablesep = false;
  652.              foreach (DataTable table in ds.Tables)
  653.              {
  654. -                if (tablesep) _output.Append(",");
  655. +                if (tablesep) _output.Append(',');
  656.                  tablesep = true;
  657.                  WriteDataTableData(table);
  658.              }
  659. @@ -248,7 +248,7 @@ namespace fastJSON
  660.              bool rowseparator = false;
  661.              foreach (DataRow row in table.Rows)
  662.              {
  663. -                if (rowseparator) _output.Append(",");
  664. +                if (rowseparator) _output.Append(',');
  665.                  rowseparator = true;
  666.                  _output.Append('[');
  667.  
  668. @@ -290,12 +290,12 @@ namespace fastJSON
  669.              {
  670.                  if (_TypesWritten == false)
  671.                  {
  672. -                    _output.Append("{");
  673. +                    _output.Append('{');
  674.                      _before = _output;
  675.                      _output = new StringBuilder();
  676.                  }
  677.                  else
  678. -                    _output.Append("{");
  679. +                    _output.Append('{');
  680.              }
  681.              _TypesWritten = true;
  682.              _current_depth++;
  683. diff --git a/fastJSON/fastJSON.csproj b/fastJSON/fastJSON.csproj
  684. index 9eabd29..ba0c013 100644
  685. --- a/fastJSON/fastJSON.csproj
  686. +++ b/fastJSON/fastJSON.csproj
  687. @@ -48,7 +48,7 @@
  688.      <OutputPath>bin\Debug\</OutputPath>
  689.      <ErrorReport>prompt</ErrorReport>
  690.      <WarningLevel>4</WarningLevel>
  691. -    <DefineConstants>-CUSTOMTYPE </DefineConstants>
  692. +    <DefineConstants>CUSTOMTYPE </DefineConstants>
  693.    </PropertyGroup>
  694.    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  695.      <DebugType>full</DebugType>
  696. @@ -74,7 +74,7 @@
  697.    <ItemGroup>
  698.      <Reference Include="System" />
  699.      <Reference Include="System.Data" />
  700. -    <Reference Include="System.Xml" />
  701. +    <Reference Include="System.XML" />
  702.    </ItemGroup>
  703.    <ItemGroup>
  704.      <Compile Include="AssemblyInfo.cs" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement