コード例 #1
0
ファイル: json.cpp プロジェクト: JoshuaBeach/minutor
JSONObject::JSONObject(JSONHelper &reader) {
  while (true) {
    Token type = reader.nextToken();
    if (type == TokenObjectClose)
      break;
    if (type != TokenString)
      throw JSONParseException("Expected quoted string", reader.location());
    QString key = reader.readString();
    if (key.length() == 0)
      throw JSONParseException("Empty object key", reader.location());
    if (reader.nextToken() != TokenKeySeparator)
      throw JSONParseException("Expected ':'", reader.location());
    JSONData *value;
    switch (reader.nextToken()) {
      case TokenNULL: value = NULL; break;
      case TokenTRUE: value = new JSONBool(true); break;
      case TokenFALSE: value = new JSONBool(false); break;
      case TokenString: value = new JSONString(reader.readString()); break;
      case TokenNumber: value = new JSONNumber(reader.readDouble()); break;
      case TokenObject: value = new JSONObject(reader); break;
      case TokenArray: value = new JSONArray(reader); break;
      default: throw JSONParseException("Expected value", reader.location());
    }
    children[key] = value;
    type = reader.nextToken();  // comma or end
    if (type == TokenObjectClose)
      break;
    if (type != TokenValueSeparator)
      throw JSONParseException("Expected ',' or '}'", reader.location());
  }
}
コード例 #2
0
ファイル: json.cpp プロジェクト: JoshuaBeach/minutor
JSONArray::JSONArray(JSONHelper &reader) {
  while (true) {
    Token type = reader.nextToken();
    if (type == TokenArrayClose)
      break;
    JSONData *value;
    switch (type) {
      case TokenNULL: value = NULL; break;
      case TokenTRUE: value = new JSONBool(true); break;
      case TokenFALSE: value = new JSONBool(false); break;
      case TokenString: value = new JSONString(reader.readString()); break;
      case TokenNumber: value = new JSONNumber(reader.readDouble()); break;
      case TokenObject: value = new JSONObject(reader); break;
      case TokenArray: value = new JSONArray(reader); break;
      default: throw JSONParseException("Expected Value", reader.location());
    }
    data.append(value);
    type = reader.nextToken();  // comma or end
    if (type == TokenArrayClose)
      break;
    if (type != TokenValueSeparator)
      throw JSONParseException("Expected ',' or ']'", reader.location());
  }
}