From 3e36831cdc0b823c84936906169357764f87041b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanchon?= Date: Wed, 23 Jul 2014 12:56:42 +0200 Subject: [PATCH] Updated README.md --- JsonParser/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/JsonParser/README.md b/JsonParser/README.md index a61c386c..8a9bda04 100644 --- a/JsonParser/README.md +++ b/JsonParser/README.md @@ -49,6 +49,13 @@ Just add the following lines at the top of your `.ino` file: #include using namespace ArduinoJson::Parser; + +> ##### Having a namespace conflict? +> To be able to use both `ArduinoJson::Generator` and `ArduinoJson::Parser` in the same file, you need to do one of the followings: +> +> * Put the `using` statements into different functions +> * `using namespace ArduinoJson`, then prefix the type names by `Generator::` or `Parser::` +> * Create aliases for the namespaces or the types (C++11 only) ### 3. Create a parser @@ -103,6 +110,14 @@ And then extract the member you need: long time = root["time"]; double latitude = root["data"][0]; double longitude = root["data"][1]; + +You can also iterate through the key-value pairs of the object: + + for (JsonObjectIterator i=root.begin(); i!=root.end(); ++i) + { + Serial.println(i.key()); + Serial.println((char*)i.value()); + } #### Array @@ -130,6 +145,13 @@ And then extract the content by its index in the array: double b = root[0][1]; double c = root[1][0]; double d = root[1][1]; + +You can also iterate through the key-value pairs of the object: + + for (JsonArrayIterator i=array.begin(); i!=array.end(); ++i) + { + Serial.println((char*)*i); + } Common pitfalls ---------------