From fe7cf55de97cb5880b384e86abf8decf66cd497f Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Sat, 23 Oct 2010 19:46:52 +0000 Subject: [PATCH] Adde comments --- src/zutil/parser/json/JSONParser.java | 108 ++++++++------------------ 1 file changed, 32 insertions(+), 76 deletions(-) diff --git a/src/zutil/parser/json/JSONParser.java b/src/zutil/parser/json/JSONParser.java index 9691dd1..5ae240e 100644 --- a/src/zutil/parser/json/JSONParser.java +++ b/src/zutil/parser/json/JSONParser.java @@ -3,10 +3,13 @@ package zutil.parser.json; import zutil.MultiPrintStream; import zutil.parser.json.JSONNode.JSONType; +/** + * This is a JSON parser class + * + * @author Ziver + */ public class JSONParser{ private String json; - private int index; - public static void main(String[] args){ JSONParser parser = new JSONParser("" + @@ -27,20 +30,44 @@ public class JSONParser{ "}"); JSONNode node = parser.read(); MultiPrintStream.out.dump( node ); - JSONWriter writer = new JSONWriter(System.out); + JSONWriter writer = new JSONWriter( System.out ); writer.write(node); } + /** + * Creates a new instance of the parser + * + * @param json is the JSON String to parse + */ public JSONParser(String json){ this.json = json; } + /** + * Starts parsing + * + * @return a JSONNode object that is the root of the JSON + */ public JSONNode read(){ - index = 0; return parse(new StringBuffer(json)); } + + /** + * Starts parsing + * + * @return a JSONNode object that is the root of the JSON + */ + /*public static JSONNode read( String json ){ + return parse(new StringBuffer(json)); + }*/ - protected JSONNode parse(StringBuffer json){ + /** + * This is the real recursive parsing method + * + * @param json + * @return + */ + protected static JSONNode parse(StringBuffer json){ JSONNode root = null; JSONNode key = null; JSONNode node = null; @@ -90,75 +117,4 @@ public class JSONParser{ return root; } - - - protected JSONNode parse2(){ - System.out.println("Recursion"); - JSONNode root = null; - - for(; index