Skip to content

Commit

Permalink
Fixed double to string conversion and array's set by index issues and…
Browse files Browse the repository at this point in the history
… add support non-object type data.
  • Loading branch information
mobizt committed Apr 19, 2022
1 parent 507ac9a commit 44257be
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 178 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The Json Parser/Editor Arduino library.


The easiest Arduino library JSON parser, builder and editor, v2.6.16
The easiest Arduino library JSON parser, builder and editor, v2.6.17

FirebaseJson is the easiest JSON manipulation library to parse or deserialize complex or nested JSON objects and arrays.

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
},
"frameworks": "arduino",
"platforms": ["espressif8266", "espressif32","teensy", "atmelsam","ststm32","atmelavr","atmelmegaavr","raspberrypi"],
"version": "2.6.16"
"version": "2.6.17"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=FirebaseJson

version=2.6.16
version=2.6.17

author=Mobizt

Expand Down
42 changes: 37 additions & 5 deletions src/FirebaseJson.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* FirebaseJson, version 2.6.16
* FirebaseJson, version 2.6.17
*
* The Easiest Arduino library to parse, create and edit JSON object using a relative path.
*
* Created April 18, 2022
* Created April 19, 2022
*
* Features
* - Using path to access node element in search style e.g. json.get(result,"a/b/c")
* - Serializing to writable objects e.g. String, C/C++ string, Client (WiFi and Ethernet), File and Hardware Serial.
* - Deserializing from const char, char array, string literal and stream e.g. Client (WiFi and Ethernet), File and
* - Serializing to writable objects e.g. String, C/C++ string, Clients (WiFi, Ethernet, and GSM), File and Hardware Serial.
* - Deserializing from const char, char array, string literal and stream e.g. Clients (WiFi, Ethernet, and GSM), File and
* Hardware Serial.
* - Use managed class, FirebaseJsonData to keep the deserialized result, which can be casted to any primitive data types.
*
Expand Down Expand Up @@ -77,7 +77,27 @@ void FirebaseJsonBase::mCopy(FirebaseJsonBase &other)
bool FirebaseJsonBase::setRaw(const char *raw)
{
mClear();
root = parse(raw);

if (raw)
{
size_t i = 0;
while (i < strlen(raw) && raw[i] == ' ')
{
i++;
}

if (raw[i] == '{' || raw[i] == '[')
{
this->root_type = (raw[i] == '{') ? Root_Type_JSON : Root_Type_JSONArray;
root = parse(raw);
}
else
{
this->root_type = Root_Type_Raw;
root = MB_JSON_CreateRaw(raw);
}
}

return root != NULL;
}

Expand Down Expand Up @@ -938,6 +958,11 @@ FirebaseJsonArray::FirebaseJsonArray(FirebaseJsonArray &other)

FirebaseJsonArray &FirebaseJsonArray::nAdd(MB_JSON *value)
{
if (root_type != Root_Type_JSONArray)
mClear();

root_type = Root_Type_JSONArray;

prepareRoot();

if (value == NULL)
Expand Down Expand Up @@ -974,6 +999,13 @@ bool FirebaseJsonArray::mGetIdx(FirebaseJsonData *result, int index, bool pretti

bool FirebaseJsonArray::mSetIdx(int index, MB_JSON *value)
{
if (root_type != Root_Type_JSONArray)
mClear();

root_type = Root_Type_JSONArray;

prepareRoot();

int size = MB_JSON_GetArraySize(root);
if (index < size)
return MB_JSON_ReplaceItemInArray(root, index, value);
Expand Down
Loading

0 comments on commit 44257be

Please sign in to comment.