OSDN Git Service

Fixed JSON parsing of a single non-object, non-array.
authorNathanSweet <nathan.sweet@gmail.com>
Sun, 12 May 2013 14:06:04 +0000 (16:06 +0200)
committerNathanSweet <nathan.sweet@gmail.com>
Sun, 12 May 2013 14:06:04 +0000 (16:06 +0200)
gdx/src/com/badlogic/gdx/utils/JsonReader.java
gdx/src/com/badlogic/gdx/utils/JsonReader.rl

index 625dd2f..1523f75 100644 (file)
@@ -437,6 +437,8 @@ public class JsonReader {
                                throw new SerializationException("Error parsing JSON, unmatched brace.");\r
                        else\r
                                throw new SerializationException("Error parsing JSON, unmatched bracket.");\r
+               } else if (parseRuntimeEx != null) {\r
+                       throw new SerializationException("Error parsing JSON: " + new String(data), parseRuntimeEx);\r
                }\r
                JsonValue root = this.root;\r
                this.root = null;\r
@@ -581,7 +583,10 @@ public class JsonReader {
 \r
        private void addChild (String name, JsonValue child) {\r
                child.setName(name);\r
-               if (current.isArray() || current.isObject())\r
+               if (current == null) {\r
+                       current = child;\r
+                       root = child;\r
+               } else if (current.isArray() || current.isObject())\r
                        current.addChild(child);\r
                else\r
                        root = current;\r
index 1351be2..89ccbb4 100644 (file)
@@ -218,7 +218,8 @@ public class JsonReader {
                        int lineNumber = 1;\r
                        for (int i = 0; i < p; i++)\r
                                if (data[i] == '\n') lineNumber++;\r
-                       throw new SerializationException("Error parsing JSON on line " + lineNumber + " near: " + new String(data, p, pe - p), parseRuntimeEx);\r
+                       throw new SerializationException("Error parsing JSON on line " + lineNumber + " near: " + new String(data, p, pe - p),\r
+                               parseRuntimeEx);\r
                } else if (elements.size != 0) {\r
                        JsonValue element = elements.peek();\r
                        elements.clear();\r
@@ -226,6 +227,8 @@ public class JsonReader {
                                throw new SerializationException("Error parsing JSON, unmatched brace.");\r
                        else\r
                                throw new SerializationException("Error parsing JSON, unmatched bracket.");\r
+               } else if (parseRuntimeEx != null) {\r
+                       throw new SerializationException("Error parsing JSON: " + new String(data), parseRuntimeEx);\r
                }\r
                JsonValue root = this.root;\r
                this.root = null;\r
@@ -239,7 +242,10 @@ public class JsonReader {
 \r
        private void addChild (String name, JsonValue child) {\r
                child.setName(name);\r
-               if (current.isArray() || current.isObject())\r
+               if (current == null) {\r
+                       current = child;\r
+                       root = child;\r
+               } else if (current.isArray() || current.isObject())\r
                        current.addChild(child);\r
                else\r
                        root = current;\r