From 18e4ef8da7c87d3f76d8945912e21c54a37f0532 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Sun, 12 May 2013 16:06:04 +0200 Subject: [PATCH] Fixed JSON parsing of a single non-object, non-array. --- gdx/src/com/badlogic/gdx/utils/JsonReader.java | 7 ++++++- gdx/src/com/badlogic/gdx/utils/JsonReader.rl | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gdx/src/com/badlogic/gdx/utils/JsonReader.java b/gdx/src/com/badlogic/gdx/utils/JsonReader.java index 625dd2ff3..1523f75a9 100644 --- a/gdx/src/com/badlogic/gdx/utils/JsonReader.java +++ b/gdx/src/com/badlogic/gdx/utils/JsonReader.java @@ -437,6 +437,8 @@ public class JsonReader { throw new SerializationException("Error parsing JSON, unmatched brace."); else throw new SerializationException("Error parsing JSON, unmatched bracket."); + } else if (parseRuntimeEx != null) { + throw new SerializationException("Error parsing JSON: " + new String(data), parseRuntimeEx); } JsonValue root = this.root; this.root = null; @@ -581,7 +583,10 @@ public class JsonReader { private void addChild (String name, JsonValue child) { child.setName(name); - if (current.isArray() || current.isObject()) + if (current == null) { + current = child; + root = child; + } else if (current.isArray() || current.isObject()) current.addChild(child); else root = current; diff --git a/gdx/src/com/badlogic/gdx/utils/JsonReader.rl b/gdx/src/com/badlogic/gdx/utils/JsonReader.rl index 1351be251..89ccbb418 100644 --- a/gdx/src/com/badlogic/gdx/utils/JsonReader.rl +++ b/gdx/src/com/badlogic/gdx/utils/JsonReader.rl @@ -218,7 +218,8 @@ public class JsonReader { int lineNumber = 1; for (int i = 0; i < p; i++) if (data[i] == '\n') lineNumber++; - throw new SerializationException("Error parsing JSON on line " + lineNumber + " near: " + new String(data, p, pe - p), parseRuntimeEx); + throw new SerializationException("Error parsing JSON on line " + lineNumber + " near: " + new String(data, p, pe - p), + parseRuntimeEx); } else if (elements.size != 0) { JsonValue element = elements.peek(); elements.clear(); @@ -226,6 +227,8 @@ public class JsonReader { throw new SerializationException("Error parsing JSON, unmatched brace."); else throw new SerializationException("Error parsing JSON, unmatched bracket."); + } else if (parseRuntimeEx != null) { + throw new SerializationException("Error parsing JSON: " + new String(data), parseRuntimeEx); } JsonValue root = this.root; this.root = null; @@ -239,7 +242,10 @@ public class JsonReader { private void addChild (String name, JsonValue child) { child.setName(name); - if (current.isArray() || current.isObject()) + if (current == null) { + current = child; + root = child; + } else if (current.isArray() || current.isObject()) current.addChild(child); else root = current; -- 2.11.0