Sfoglia il codice sorgente

修复反序列化配置数据时,LitJson不支持float类型的错误 (#117)

ks 6 anni fa
parent
commit
8694e415b6

+ 7 - 0
Unity/Assets/ThirdParty/ILRuntime/LitJson/JsonMapper.cs

@@ -714,6 +714,8 @@ namespace LitJson
             };
             RegisterImporter (base_importers_table, typeof (string),
                               typeof (DateTime), importer);
+            
+            RegisterImporter<double, float>(input => Convert.ToSingle(input));
         }
 
         private static void RegisterImporter (
@@ -754,6 +756,11 @@ namespace LitJson
                 writer.Write ((string) obj);
                 return;
             }
+            
+            if (obj is Single) {
+                writer.Write((float)obj);
+                return;
+            }
 
             if (obj is Double) {
                 writer.Write ((double) obj);

+ 12 - 1
Unity/Assets/ThirdParty/ILRuntime/LitJson/JsonWriter.cs

@@ -225,7 +225,7 @@ namespace LitJson
 
             writer.Write ('"');
 
-	        //直接存储原始字符串,不再做任何转义字符的解析
+	        //直锟接存储原始锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟轿猴拷转锟斤拷锟街凤拷锟侥斤拷锟斤拷
 	        writer.Write(str);
 	        writer.Write('"');
 	        return;
@@ -464,5 +464,16 @@ namespace LitJson
 
             context.ExpectingValue = true;
         }
+        
+        public void Write(float number)
+        {
+            DoValidation(Condition.Value);
+            PutNewline();
+ 
+            string str = number.ToString();
+            Put(str);
+ 
+            context.ExpectingValue = false;
+        }
     }
 }