Updated README.md

This commit is contained in:
Benoît Blanchon
2014-07-23 12:56:42 +02:00
parent 5129f3400c
commit 3e36831cdc

View File

@ -50,6 +50,13 @@ Just add the following lines at the top of your `.ino` file:
using namespace ArduinoJson::Parser; 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 ### 3. Create a parser
To extract data from the JSON string, you need to create a `JsonParser`, and specify the number of token you allocate for the parser itself: To extract data from the JSON string, you need to create a `JsonParser`, and specify the number of token you allocate for the parser itself:
@ -104,6 +111,14 @@ And then extract the member you need:
double latitude = root["data"][0]; double latitude = root["data"][0];
double longitude = root["data"][1]; 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 #### Array
Consider we have a `char json[]` containing to the following JSON string: Consider we have a `char json[]` containing to the following JSON string:
@ -131,6 +146,13 @@ And then extract the content by its index in the array:
double c = root[1][0]; double c = root[1][0];
double d = root[1][1]; 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 Common pitfalls
--------------- ---------------