Revision: 2378
http://sourceforge.net/p/swingme/code/2378
Author: yuranet
Date: 2019-09-19 12:12:33 +0000 (Thu, 19 Sep 2019)
Log Message:
-----------
se json parser
Modified Paths:
--------------
UtilME/build.xml
Added Paths:
-----------
UtilME/src_se/
UtilME/src_se/net/
UtilME/src_se/net/yura/
UtilME/src_se/net/yura/io/
UtilME/src_se/net/yura/io/JSONUtil.java
Modified: UtilME/build.xml
===================================================================
--- UtilME/build.xml 2019-06-20 11:27:02 UTC (rev 2377)
+++ UtilME/build.xml 2019-09-19 12:12:33 UTC (rev 2378)
@@ -18,7 +18,7 @@
<mkdir dir="build"/>
<mkdir dir="dist"/>
- <javac debug="on" srcdir="src" destdir="build" source="1.4" target="1.4" classpath="lib/xmlpull_1_1_3_1.jar"/>
+ <javac debug="on" srcdir="src:src_se" destdir="build" source="1.5" target="1.5" classpath="lib/xmlpull_1_1_3_1.jar"/>
<unzip src="lib/xmlpull_1_1_3_1.jar" dest="build"/>
Added: UtilME/src_se/net/yura/io/JSONUtil.java
===================================================================
--- UtilME/src_se/net/yura/io/JSONUtil.java (rev 0)
+++ UtilME/src_se/net/yura/io/JSONUtil.java 2019-09-19 12:12:33 UTC (rev 2378)
@@ -0,0 +1,64 @@
+package net.yura.io;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import net.yura.mobile.io.json.JSONTokener;
+import net.yura.mobile.io.json.JSONWriter;
+
+// use maps, to allow for null values
+public class JSONUtil extends net.yura.mobile.io.JSONUtil {
+
+ public JSONUtil() {
+ useListForArray = true;
+ }
+
+ protected Object readObject(JSONTokener x) throws IOException {
+ char c = x.nextClean();
+ x.back();
+ if (c == '{') {
+ x.startObject();
+ if (x.nextClean() == '}') {
+ return Collections.emptyMap();
+ } else {
+ x.back();
+ Map<String, Object> map = new HashMap<>(); // we HAVE to use HashMap, as Hashtable does not allow null values
+ for (boolean end = false; !end; end = x.endObject()) {
+ String key = x.nextKey();
+ Object obj = this.readObject(x);
+ map.put(key, obj);
+ }
+ return map;
+ }
+ }
+ return super.readObject(x);
+ }
+
+ @Override
+ protected void saveObject(JSONWriter serializer, Object object) throws IOException {
+ if (object instanceof List && !(object instanceof java.util.Vector)) {
+ List list = (List) object;
+ serializer.array();
+ for (Object obj : list) {
+ saveObject(serializer, obj);
+ }
+ serializer.endArray();
+ }
+ else if (object instanceof Map && !(object instanceof java.util.Hashtable)) {
+ Map<String, Object> map = (Map<String, Object>) object;
+ serializer.object();
+ for (String key : map.keySet()) {
+ Object value = map.get(key);
+ serializer.key(key);
+ saveObject(serializer, value);
+ }
+ serializer.endObject();
+ }
+ else {
+ super.saveObject(serializer, object);
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|