Created
November 9, 2020 18:31
-
-
Save rveitch/de1c4d4879fd7ecc8ed2e9300415e1c1 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
// ArduinoJson - arduinojson.org | |
// Copyright Benoit Blanchon 2014-2020 | |
// MIT License | |
// | |
// This example shows how to deserialize a JSON document with ArduinoJson. | |
#include <iostream> | |
#include "ArduinoJson.h" | |
int main() { | |
// Allocate the JSON document | |
// | |
// Inside the brackets, 200 is the capacity of the memory pool in bytes. | |
// Don't forget to change this value to match your JSON document. | |
// Use arduinojson.org/v6/assistant to compute the capacity. | |
StaticJsonDocument<300> doc; | |
// StaticJsonDocument<N> allocates memory on the stack, it can be | |
// replaced by DynamicJsonDocument which allocates in the heap. | |
// | |
// DynamicJsonDocument doc(200); | |
// JSON input string. | |
// | |
// Using a char[], as shown here, enables the "zero-copy" mode. This mode uses | |
// the minimal amount of memory because the JsonDocument stores pointers to | |
// the input buffer. | |
// If you use another type of input, ArduinoJson must copy the strings from | |
// the input to the JsonDocument, so you need to increase the capacity of the | |
// JsonDocument. | |
char json[] = | |
"{\"0\":{\"pc\":1,\"ccn\":10,\"ccv\":1},\"1\":{\"pc\":1,\"ccn\":11,\"ccv\":1},\"2\":{\"pc\":1,\"ccn\":12,\"ccv\":1},\"3\":{\"pc\":1,\"ccn\":13,\"ccv\":1},\"4\":{\"pc\":1,\"ccn\":14,\"ccv\":1},\"5\":{\"pc\":1,\"ccn\":15,\"ccv\":1},\"6\":{\"pc\":1,\"ccn\":16,\"ccv\":1},\"7\":{\"pc\":1,\"ccn\":17,\"ccv\":1},\"8\":{\"pc\":1,\"ccn\":18,\"ccv\":1},\"9\":{\"pc\":1,\"ccn\":19,\"ccv\":1},\"10\":{\"pc\":1,\"ccn\":20,\"ccv\":1},\"11\":{\"pc\":1,\"ccn\":21,\"ccv\":1},\"12\":{\"pc\":2,\"ccn\":10,\"ccv\":1},\"13\":{\"pc\":2,\"ccn\":11,\"ccv\":1},\"14\":{\"pc\":2,\"ccn\":12,\"ccv\":1},\"15\":{\"pc\":2,\"ccn\":13,\"ccv\":1},\"16\":{\"pc\":2,\"ccn\":14,\"ccv\":1},\"17\":{\"pc\":2,\"ccn\":15,\"ccv\":1},\"18\":{\"pc\":2,\"ccn\":16,\"ccv\":1},\"19\":{\"pc\":2,\"ccn\":17,\"ccv\":1},\"20\":{\"pc\":2,\"ccn\":18,\"ccv\":1},\"21\":{\"pc\":2,\"ccn\":19,\"ccv\":1},\"22\":{\"pc\":2,\"ccn\":20,\"ccv\":1},\"23\":{\"pc\":2,\"ccn\":21,\"ccv\":1},\"24\":{\"pc\":3,\"ccn\":10,\"ccv\":1},\"25\":{\"pc\":3,\"ccn\":11,\"ccv\":1},\"26\":{\"pc\":3,\"ccn\":12,\"ccv\":1},\"27\":{\"pc\":3,\"ccn\":13,\"ccv\":1},\"28\":{\"pc\":3,\"ccn\":14,\"ccv\":1},\"29\":{\"pc\":3,\"ccn\":15,\"ccv\":1},\"30\":{\"pc\":3,\"ccn\":16,\"ccv\":1},\"31\":{\"pc\":3,\"ccn\":17,\"ccv\":1},\"32\":{\"pc\":3,\"ccn\":18,\"ccv\":1},\"33\":{\"pc\":3,\"ccn\":19,\"ccv\":1},\"34\":{\"pc\":3,\"ccn\":20,\"ccv\":1},\"35\":{\"pc\":3,\"ccn\":21,\"ccv\":1},\"36\":{\"pc\":4,\"ccn\":10,\"ccv\":1},\"37\":{\"pc\":4,\"ccn\":11,\"ccv\":1},\"38\":{\"pc\":4,\"ccn\":12,\"ccv\":1},\"39\":{\"pc\":4,\"ccn\":13,\"ccv\":1},\"40\":{\"pc\":4,\"ccn\":14,\"ccv\":1},\"41\":{\"pc\":4,\"ccn\":15,\"ccv\":1},\"42\":{\"pc\":4,\"ccn\":16,\"ccv\":1},\"43\":{\"pc\":4,\"ccn\":17,\"ccv\":1},\"44\":{\"pc\":4,\"ccn\":18,\"ccv\":1},\"45\":{\"pc\":4,\"ccn\":19,\"ccv\":1},\"46\":{\"pc\":4,\"ccn\":20,\"ccv\":1},\"47\":{\"pc\":4,\"ccn\":21,\"ccv\":1},\"48\":{\"pc\":5,\"ccn\":10,\"ccv\":1},\"49\":{\"pc\":5,\"ccn\":11,\"ccv\":1},\"50\":{\"pc\":5,\"ccn\":12,\"ccv\":1},\"51\":{\"pc\":5,\"ccn\":13,\"ccv\":1},\"52\":{\"pc\":5,\"ccn\":14,\"ccv\":1},\"53\":{\"pc\":5,\"ccn\":15,\"ccv\":1},\"54\":{\"pc\":5,\"ccn\":16,\"ccv\":1},\"55\":{\"pc\":5,\"ccn\":17,\"ccv\":1},\"56\":{\"pc\":5,\"ccn\":18,\"ccv\":1},\"57\":{\"pc\":5,\"ccn\":19,\"ccv\":1},\"58\":{\"pc\":5,\"ccn\":20,\"ccv\":1},\"59\":{\"pc\":5,\"ccn\":21,\"ccv\":1},\"60\":{\"pc\":6,\"ccn\":10,\"ccv\":1},\"61\":{\"pc\":6,\"ccn\":11,\"ccv\":1},\"62\":{\"pc\":6,\"ccn\":12,\"ccv\":1},\"63\":{\"pc\":6,\"ccn\":13,\"ccv\":1},\"64\":{\"pc\":6,\"ccn\":14,\"ccv\":1},\"65\":{\"pc\":6,\"ccn\":15,\"ccv\":1},\"66\":{\"pc\":6,\"ccn\":16,\"ccv\":1},\"67\":{\"pc\":6,\"ccn\":17,\"ccv\":1},\"68\":{\"pc\":6,\"ccn\":18,\"ccv\":1},\"69\":{\"pc\":6,\"ccn\":19,\"ccv\":1},\"70\":{\"pc\":6,\"ccn\":20,\"ccv\":1},\"71\":{\"pc\":6,\"ccn\":21,\"ccv\":1},\"72\":{\"pc\":7,\"ccn\":10,\"ccv\":1},\"73\":{\"pc\":7,\"ccn\":11,\"ccv\":1},\"74\":{\"pc\":7,\"ccn\":12,\"ccv\":1},\"75\":{\"pc\":7,\"ccn\":13,\"ccv\":1},\"76\":{\"pc\":7,\"ccn\":14,\"ccv\":1},\"77\":{\"pc\":7,\"ccn\":15,\"ccv\":1},\"78\":{\"pc\":7,\"ccn\":16,\"ccv\":1},\"79\":{\"pc\":7,\"ccn\":17,\"ccv\":1},\"80\":{\"pc\":7,\"ccn\":18,\"ccv\":1},\"81\":{\"pc\":7,\"ccn\":19,\"ccv\":1},\"82\":{\"pc\":7,\"ccn\":20,\"ccv\":1},\"83\":{\"pc\":7,\"ccn\":21,\"ccv\":1},\"84\":{\"pc\":8,\"ccn\":10,\"ccv\":1},\"85\":{\"pc\":8,\"ccn\":11,\"ccv\":1},\"86\":{\"pc\":8,\"ccn\":12,\"ccv\":1},\"87\":{\"pc\":8,\"ccn\":13,\"ccv\":1},\"88\":{\"pc\":8,\"ccn\":14,\"ccv\":1},\"89\":{\"pc\":8,\"ccn\":15,\"ccv\":1},\"90\":{\"pc\":8,\"ccn\":16,\"ccv\":1},\"91\":{\"pc\":8,\"ccn\":17,\"ccv\":1},\"92\":{\"pc\":8,\"ccn\":18,\"ccv\":1},\"93\":{\"pc\":8,\"ccn\":19,\"ccv\":1},\"94\":{\"pc\":8,\"ccn\":20,\"ccv\":1},\"95\":{\"pc\":8,\"ccn\":21,\"ccv\":1},\"96\":{\"pc\":9,\"ccn\":10,\"ccv\":1},\"97\":{\"pc\":9,\"ccn\":11,\"ccv\":1},\"98\":{\"pc\":9,\"ccn\":12,\"ccv\":1},\"99\":{\"pc\":9,\"ccn\":13,\"ccv\":1},\"100\":{\"pc\":9,\"ccn\":14,\"ccv\":1},\"101\":{\"pc\":9,\"ccn\":15,\"ccv\":1},\"102\":{\"pc\":9,\"ccn\":16,\"ccv\":1},\"103\":{\"pc\":9,\"ccn\":17,\"ccv\":1},\"104\":{\"pc\":9,\"ccn\":18,\"ccv\":1},\"105\":{\"pc\":9,\"ccn\":19,\"ccv\":1},\"106\":{\"pc\":9,\"ccn\":20,\"ccv\":1},\"107\":{\"pc\":9,\"ccn\":21,\"ccv\":1},\"108\":{\"pc\":10,\"ccn\":10,\"ccv\":1},\"109\":{\"pc\":10,\"ccn\":11,\"ccv\":1},\"110\":{\"pc\":10,\"ccn\":12,\"ccv\":1},\"111\":{\"pc\":10,\"ccn\":13,\"ccv\":1},\"112\":{\"pc\":10,\"ccn\":14,\"ccv\":1},\"113\":{\"pc\":10,\"ccn\":15,\"ccv\":1},\"114\":{\"pc\":10,\"ccn\":16,\"ccv\":1},\"115\":{\"pc\":10,\"ccn\":17,\"ccv\":1},\"116\":{\"pc\":10,\"ccn\":18,\"ccv\":1},\"117\":{\"pc\":10,\"ccn\":19,\"ccv\":1},\"118\":{\"pc\":10,\"ccn\":20,\"ccv\":1},\"119\":{\"pc\":10,\"ccn\":21,\"ccv\":1},\"120\":{\"pc\":11,\"ccn\":10,\"ccv\":1},\"121\":{\"pc\":11,\"ccn\":11,\"ccv\":1},\"122\":{\"pc\":11,\"ccn\":12,\"ccv\":1},\"123\":{\"pc\":11,\"ccn\":13,\"ccv\":1},\"124\":{\"pc\":11,\"ccn\":14,\"ccv\":1},\"125\":{\"pc\":11,\"ccn\":15,\"ccv\":1},\"126\":{\"pc\":11,\"ccn\":16,\"ccv\":1},\"127\":{\"pc\":11,\"ccn\":17,\"ccv\":1}}"; | |
// Deserialize the JSON document | |
DeserializationError error = deserializeJson(doc, json); | |
// Test if parsing succeeds. | |
if (error) { | |
std::cerr << "deserializeJson() failed: " << error.c_str() << std::endl; | |
return 1; | |
} | |
// Fetch values. | |
// | |
// Most of the time, you can rely on the implicit casts. | |
// In other case, you can do doc["time"].as<long>(); | |
//const char* sensor = doc["sensor"]; | |
//long time = doc["time"]; | |
//double latitude = doc["data"][0]; | |
int pc = doc["0"]["pc"]; | |
// Print values. | |
std::cout << pc << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment