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; }
public static JSONObject ParseJsonString(Stream inputStream) { JSONParser parser = new JSONParser(inputStream); return parser.Root; }
public JSONObject DoConstruction(string ch, JSONParser parser) { if (ch.Equals(",") || ch.Equals("]") || ch.Equals("}")) { return objBuidling; } return null; }
public JSONObject DoConstruction(string ch, JSONParser parser) { if (ch.Equals("\"")) { // finished string objectBuilding = strBuilder.ToString(); return objectBuilding; } else { strBuilder.Append(ch); } return null; }
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; }