1 /* This file is part of QJson
3 * Copyright (C) 2008 Flavio Castelli <flavio.castelli@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License version 2.1, as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #ifndef QJSON_PARSER_H
22 #define QJSON_PARSER_H
24 #include "qjson_export.h"
34 * @brief Main class used to convert JSON data to QVariant objects
36 class QJSON_EXPORT Parser
43 * Read JSON string from the I/O Device and converts it to a QVariant object
44 * @param io Input output device
45 * @param ok if a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
46 * @returns a QVariant object generated from the JSON string
48 QVariant parse(QIODevice* io, bool* ok = 0);
51 * This is a method provided for convenience.
52 * @param jsonData data containing the JSON object representation
53 * @param ok if a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
54 * @returns a QVariant object generated from the JSON string
58 QVariant parse(const QByteArray& jsonData, bool* ok = 0);
61 * This method returns the error message
62 * @returns a QString object containing the error message of the last parse operation
65 QString errorString() const;
68 * This method returns line number where the error occurred
69 * @returns the line number where the error occurred
72 int errorLine() const;
75 * Sets whether special numbers (Infinity, -Infinity, NaN) are allowed as an extension to
77 * @param allowSpecialNumbers new value of whether special numbers are allowed
78 * @sa specialNumbersAllowed
80 void allowSpecialNumbers(bool allowSpecialNumbers);
83 * @returns whether special numbers (Infinity, -Infinity, NaN) are allowed
84 * @sa allowSpecialNumbers
86 bool specialNumbersAllowed() const;
89 Q_DISABLE_COPY(Parser)
90 ParserPrivate* const d;
94 #endif // QJSON_PARSER_H