Last active
August 29, 2015 14:03
-
-
Save bblanchon/60224e9dcfeab4ddc7e9 to your computer and use it in GitHub Desktop.
Comparison of JSON encoding libraries for Arduino
This file contains hidden or 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
#include <aJSON.h> | |
void setup() | |
{ | |
Serial.begin(9600); | |
char sensor[] = "outdoor"; | |
float value = 25.6; | |
Serial.println(sensor); | |
Serial.println(value); | |
aJsonObject *root; | |
root=aJson.createObject(); | |
aJson.addStringToObject(root, "sensor", sensor); | |
aJson.addNumberToObject(root, "value", value); | |
char* string = aJson.print(root); | |
Serial.println(string); | |
free(string); | |
aJson.deleteItem(root); | |
} | |
void loop() | |
{ | |
} |
This file contains hidden or 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
#include <JsonGenerator.h> | |
using namespace ArduinoJson::Generator; | |
void setup() | |
{ | |
Serial.begin(9600); | |
char sensor[] = "outdoor"; | |
float value = 25.6; | |
Serial.println(sensor); | |
Serial.println(value); | |
JsonHashTable<2> hashTable; | |
hashTable.add("sensor", sensor); | |
hashTable.add("value", value); | |
Serial.println(hashTable); | |
} | |
void loop() | |
{ | |
} |
This file contains hidden or 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
#include <JsonGenerator.h> | |
using namespace ArduinoJson::Generator; | |
void setup() | |
{ | |
Serial.begin(9600); | |
char sensor[] = "outdoor"; | |
float value = 25.6; | |
Serial.println(sensor); | |
Serial.println(value); | |
JsonObject<2> object; | |
object["sensor"] = sensor; | |
object["value"] = value; | |
Serial.println(object); | |
} | |
void loop() | |
{ | |
} |
This file contains hidden or 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
void setup() | |
{ | |
Serial.begin(9600); | |
char sensor[] = "outdoor"; | |
float value = 25.6; | |
Serial.println(sensor); | |
Serial.println(value); | |
Serial.println("{\"sensor\":\"outdoor\",\"value\":25.6}"); | |
} | |
void loop() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment