2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FWebJsonJsonParser.h
20 * @brief This is the header file for the %JsonParser class.
22 * This header file contains the declarations of the JSON functionalities for parsing the JSON-encoded file.
24 #ifndef _FWEB_JSON_JSON_PARSER_H_
25 #define _FWEB_JSON_JSON_PARSER_H_
27 #include <FBaseByteBuffer.h>
29 namespace Tizen { namespace Web { namespace Json
32 class _JsonParserImpl;
33 }}} // Tizen::Web::Json
35 namespace Tizen { namespace Web { namespace Json
40 * @brief This class contains the declarations of the JSON functionalities for parsing the JSON-encoded file.
44 * The %JsonParser class contains the declarations of the JSON functionalities for parsing the JSON-encoded files.
46 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
48 * The following example demonstrates how to use the %JsonParser methods.
51 * Sample Data - JsonSample.json
55 * "title": "Is an Icon List",
56 * "name": "main_window",
61 * "src": "Images/fun.png",
65 * "data": "Click Here",
71 * {"alignment" : "center"},
72 * {"transperancy":"80"}
76 * #include <FWebJson.h>
78 * using namespace Tizen::Base;
79 * using namespace Tizen::Base::Utility;
80 * using namespace Tizen::Web::Json;
83 * MyClass::JsonParserSample(void)
86 * String fileName(L"/Home/JsonSample.json");
87 * IJsonValue* pValue = JsonParser::ParseN(fileName);
88 * if( pValue == null )
90 * AppLog("ErrorCode %s", GetLastResult());
94 * // Uses the pValue to know what is the type
95 * if( pValue->GetType() == JSON_TYPE_OBJECT )
97 * JsonObject* pJsonObj = static_cast<JsonObject*>(pValue);//use pJsonObj to access key-value pairs
98 * pJsonObj->RemoveAll(true);
100 * else if( pValue->GetType() == JSON_TYPE_ARRAY )
102 * JsonArray* pJsonArray = static_cast<JsonArray*>(pValue);//use pJsonArray to access values
103 * pJsonArray->RemoveAll(true);
108 * // Parses from char*
109 * const char* jBuf = "{\"Key\":1,\"Key1\":{\"Key2\":\"val\",\"Key3\":\"val1\"},\"Key4\":[\"val2\",\"val3\"]}";
111 * int length = str.GetLength();
112 * IJsonValue* pValue1 = JsonParser::ParseN(jBuf, length);
114 * // Converts the pValue1 to JsonObject
115 * JsonObject* pJsonObject = static_cast<JsonObject*>(pValue1);
116 * pJsonObject->RemoveAll(true);
117 * delete pJsonObject;
119 * // Parses from ByteBuffer
120 * ByteBuffer *pBuf = StringUtil::StringToUtf8N( str );
121 * IJsonValue* pValue2 = JsonParser::ParseN(*pBuf);
123 * // Converts the pValue2 to JsonObject
124 * pJsonObject = static_cast<JsonObject*>(pValue2);
125 * pJsonObject->RemoveAll(true);
126 * delete pJsonObject;
131 class _OSP_EXPORT_ JsonParser
135 * Parses a JSON-encoded file to IJsonValue (node).
138 * @brief <i> [Compatibility] </i>
142 * @compatibility This method has compatibility issues with OSP compatible applications. @n
143 * For more information, see @ref CompIoPathPage "here".
146 * @return A JSON value of type JsonArray or JsonObject, @n
147 * else @c null if the JSON data of the file is invalid
148 * @param[in] filePath The path of the JSON-encoded file
149 * @exception E_SUCCESS The method is successful.
150 * @exception E_INVALID_ARG The specified file path is incorrect, or the file is not found.
151 * @exception E_INVALID_DATA The input JSON data is invalid, or the buffer is empty.
152 * @exception E_MAX_EXCEEDED The input JSON data exceeds the maximum length.
153 * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
154 * @exception E_FILE_NOT_FOUND The specified @c filePath cannot be found.
155 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
156 * @remarks The specific error code can be accessed using the GetLastResult() method.
158 static IJsonValue* ParseN(const Tizen::Base::String& filePath);
161 * Parses a JSON-encoded buffer to IJsonValue (node).
165 * @return A JSON value of type JsonArray or JsonObject, @n
166 * else @c null if the JSON data of the file is invalid
167 * @param[in] pBuffer A JSON-encoded buffer
168 * @param[in] bufferLength A JSON-encoded buffer length
169 * @exception E_SUCCESS The method is successful.
170 * @exception E_INVALID_ARG Either of the following conditions has occurred:
171 * - The specified @c pBuffer is @c null.
172 * - The specified @c bufferLength is zero or negative.
173 * @exception E_INVALID_DATA The input JSON data is invalid, or the buffer is empty.
174 * @exception E_MAX_EXCEEDED The input JSON data exceeds the maximum length.
175 * @remarks The specific error code can be accessed using the GetLastResult() method.
177 static IJsonValue* ParseN(const void* pBuffer, int bufferLength);
180 * Parses a JSON-encoded Tizen::Base::ByteBuffer to IJsonValue (node).
184 * @return A JSON value of type JsonArray or JsonObject, @n
185 * else @c null if the JSON data of the file is invalid
186 * @param[in] buffer A JSON-encoded byte buffer
187 * @exception E_SUCCESS The method is successful.
188 * @exception E_INVALID_DATA The input JSON data is invalid, or the buffer is empty.
189 * @exception E_MAX_EXCEEDED The input JSON data exceeds the maximum length.
190 * @remarks The specific error code can be accessed using the GetLastResult() method.
192 static IJsonValue* ParseN(const Tizen::Base::ByteBuffer& buffer);
196 // This default constructor is intentionally declared as private because this class cannot be constructed.
198 // @remarks This constructor is hidden.
203 // This is the destructor for this class.
205 // @remarks This constructor is hidden.
207 virtual ~JsonParser(void);
210 _JsonParserImpl* __pJsonParserImpl;
212 friend class _JsonParserImpl;
215 }}} // Tizen::Web::Json
216 #endif // _FWEB_JSON_JSON_PARSER_H_