8000 Merge branch 'master' of https://github.com/nkolban/esp32-snippets.git · markingle/esp32-snippets@d0886e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit d0886e0

Browse files
committed
2 parents 6bbd173 + dc17e79 commit d0886e0

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

cpp_utils/JSON.cpp

Lines changed: 21 additions & 0 deletions
< 8000 td data-grid-cell-id="diff-d5171a7579b94b145a710cd825d0f2901c2ccb6d01b8e1e307c975cdbcd07b11-175-175-0" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">175
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,27 @@ std::string JsonArray::getString(int item) {
175
} // getString
176176

177177

178+
/**
179+
* @brief Convert the JSON array to a string.
180+
* @return A JSON string representation of the array.
181+
*/
182+
std::string JsonArray::toString() {
183+
char *data = cJSON_Print(m_node);
184+
std::string ret(data);
185+
free(data);
186+
return ret;
187+
} // toString
188+
189+
190+
/**
191+
* @brief Get the number of elements from the array.
192+
* @return The int value that represents the number of elements.
193+
*/
194+
std::size_t JsonArray::size() {
195+
return cJSON_GetArraySize(m_node);
196+
} // size
197+
198+
178199
JsonObject::JsonObject(cJSON* node) {
179200
m_node = node;
180201
}

cpp_utils/JSON.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class JsonArray {
4444
void addInt(int value);
4545
void addObject(JsonObject value);
4646
void addString(std::string value);
47+
std::string toString();
48+
std::size_t size();
4749
/**
4850
* @brief The underlying cJSON node.
4951
*/

0 commit comments

Comments
 (0)
0