Beispiel #1
0
        public JSONObject DoConstruction(string ch, JSONParser parser)
        {
            foreach (string keyPattern in JSONParser.tokenDict.Keys) {
                if (System.Text.RegularExpressions.Regex.IsMatch(ch, keyPattern)) {
                    IJsonConstruct nextAction;
                    if (JSONParser.tokenDict[keyPattern] == typeof(ConstructBoolean) || JSONParser.tokenDict[keyPattern] == typeof(ConstructDouble)) {
                        nextAction = (IJsonConstruct)JSONParser.tokenDict[keyPattern].GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { ch });
                    } else {
                        nextAction = (IJsonConstruct)JSONParser.tokenDict[keyPattern].GetConstructor(new Type[] { }).Invoke(null);
                    }
                    parser.AddToStack(nextAction);
                    return null;
                }
            }

            // ignore whitespace
            if (System.Text.RegularExpressions.Regex.IsMatch(ch, @"\s+")) {
                return null;
            }

            if (ch.Equals("]")) {
                return objectBuilding;
            } else if (ch.Equals(",")) {
                return null;
            } else {
                throw new ArgumentException("Unexpected character while building object: " + ch);
            }

            return null;
        }
Beispiel #2
0
 public static JSONObject ParseJsonString(Stream inputStream)
 {
     JSONParser parser = new JSONParser(inputStream);
     return parser.Root;
 }
Beispiel #3
0
 public JSONObject DoConstruction(string ch, JSONParser parser)
 {
     if (ch.Equals(",") || ch.Equals("]") || ch.Equals("}")) {
         return objBuidling;
     }
     return null;
 }
Beispiel #4
0
 public JSONObject DoConstruction(string ch, JSONParser parser)
 {
     if (ch.Equals("\"")) {
         // finished string
         objectBuilding = strBuilder.ToString();
         return objectBuilding;
     } else {
         strBuilder.Append(ch);
     }
     return null;
 }
Beispiel #5
0
 public JSONObject DoConstruction(string ch, JSONParser parser)
 {
     if (ch.Equals(",") || ch.Equals("]") || ch.Equals("}")) {
         // return object
         objBuilding = Double.Parse(strBuilder.ToString());
         return objBuilding;
     } else {
         strBuilder.Append(ch);
     }
     return null;
 }