Created
February 24, 2022 18:40
-
-
Save okram/faa1b0951cff1853da2e58c89c762e2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static JsonObject toJson(const byte *payload, const uint32_t length) { | |
char *json = (char *)malloc(length); | |
memcpy(json, payload, length); | |
if (json[0] == NULL) { | |
json = json + 2; | |
} | |
json[length - 1] = NULL; | |
StaticJsonDocument<256> doc; | |
DeserializationError error = deserializeJson(doc, json); | |
if (error) { | |
Serial.println(error.c_str()); | |
return JsonObject(); | |
} else | |
return doc.to<JsonObject>(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment