Added JsonParserBase::parse() that returns a JsonValue

This commit is contained in:
Benoît Blanchon
2014-07-17 12:37:35 +02:00
parent 73eda08dd4
commit b6e3a37ad9
3 changed files with 9 additions and 10 deletions

View File

@ -7,13 +7,13 @@
using namespace ArduinoJson::Parser; using namespace ArduinoJson::Parser;
jsmntok_t* JsonParserBase::parse(char* json) JsonValue JsonParserBase::parse(char* json)
{ {
jsmn_parser parser; jsmn_parser parser;
jsmn_init(&parser); jsmn_init(&parser);
if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, maxTokens)) if (JSMN_SUCCESS != jsmn_parse(&parser, json, tokens, maxTokens))
return 0; return JsonValue();
return tokens; return JsonValue(json, tokens);
} }

View File

@ -21,15 +21,17 @@ namespace ArduinoJson
{ {
} }
JsonValue parse(char* json);
/* /*
* Parse the JSON string and return a array. * Parse the JSON string and return a array.
* *
* The content of the string may be altered to add '\0' at the * The content of the string may be altered to add '\0' at the
* end of string tokens * end of string tokens
*/ */
JsonArray parseArray(char* json) DEPRECATED JsonArray parseArray(char* json)
{ {
return JsonArray(json, parse(json)); return (JsonArray)parse(json);
} }
/* /*
@ -38,16 +40,14 @@ namespace ArduinoJson
* The content of the string may be altered to add '\0' at the * The content of the string may be altered to add '\0' at the
* end of string tokens * end of string tokens
*/ */
JsonHashTable parseHashTable(char* json) DEPRECATED JsonHashTable parseHashTable(char* json)
{ {
return JsonHashTable(json, parse(json)); return (JsonHashTable)parse(json);
} }
private: private:
jsmntok_t* tokens; jsmntok_t* tokens;
int maxTokens; int maxTokens;
jsmntok_t* parse(char* json);
}; };
} }
} }

View File

@ -6,7 +6,6 @@
#pragma once #pragma once
#include "jsmn.h" #include "jsmn.h"
#include "JsonObjectBase.h" #include "JsonObjectBase.h"
namespace ArduinoJson namespace ArduinoJson