public JSONValue getJSON() { JKeyValue keyValue = new JKeyValue(); List <JKeyValue> list = new List <JKeyValue> { }; JSONValue jValue; Token token; while (char.IsWhiteSpace(t.input.peek())) { token = t.tokenize(); } if (t.input.peek() == '{') { jValue = getObject(); } else if (t.input.peek() == '[') { jValue = getArray(); } else { token = t.tokenize(); if (token.Type == "bool" || token.Type == "null") { jValue = this.parse(token); Console.Write(token.Value); } else { throw new Exception("not object"); } } return(jValue); }
public JObject getObject() { JKeyValue keyValue = new JKeyValue(); List <JKeyValue> list = new List <JKeyValue> { }; JObject jsonObject = new JObject(); Token token; token = t.tokenize(); Console.Write(token.Value); while (this.input.hasMore()) { token = t.tokenize(); while (token != null && token.Type == "whitespace") { Console.Write(token.Value); token = t.tokenize(); } //key token if (token != null && token.Type == "string") { Console.Write(token.Value); keyValue.key = token.Value; } else { throw new Exception("Not a key"); } token = t.tokenize(); while (token != null && token.Type == "whitespace") { Console.Write(token.Value); token = t.tokenize(); } // token == : if (token.Type == "colon") { Console.Write(token.Value); // } else { throw new Exception("Error no colon"); } while (char.IsWhiteSpace(t.input.peek())) { token = t.tokenize(); Console.Write(token.Value); } //token == value if (t.input.peek() == '{') { JObject o = getObject(); keyValue.value = o; } else if (t.input.peek() == '[') { JArray arr = getArray(); keyValue.value = arr; } else { token = t.tokenize(); Console.Write(token.Value); keyValue.value = this.parse(token); } list.Add(keyValue); keyValue = new JKeyValue(); //check for , or } token = t.tokenize(); while (token.Type == "whitespace") { Console.Write(token.Value); token = t.tokenize(); } if (token.Type != "comma" && token.Type != "closingBrace") { break; } else if (token.Type == "closingBrace") { Console.Write(token.Value); break; } else { Console.Write(token.Value); } } jsonObject.value = list; return(jsonObject); }