Updated README.md

This commit is contained in:
Benoit Blanchon
2014-07-05 16:09:37 +02:00
parent efd8c0ff5c
commit 935cb068ab
2 changed files with 31 additions and 34 deletions

View File

@ -1,11 +1,11 @@
An efficient JSON parser for Arduino Arduino JSON library - Parser
==================================== =============================
This library is an thin C++ wrapper around the *jsmn* tokenizer: http://zserge.com/jsmn.html This library is an thin C++ wrapper around the *jsmn* tokenizer: http://zserge.com/jsmn.html
It's design to be very lightweight, works without any allocation on the heap (no malloc) and supports nested objects. It's design to be very lightweight, works without any allocation on the heap (no malloc) and supports nested objects.
It has been written with Arduino in mind, but it isn't linked to Arduino libraries so you can use this library on any other C++ project. It has been written with Arduino in mind, but it isn't linked to Arduino libraries so you can use this library in any other C++ project.
Features Features
@ -13,33 +13,26 @@ Features
* Based on the well-proven [jsmn](http://zserge.com/jsmn.html) tokenizer * Based on the well-proven [jsmn](http://zserge.com/jsmn.html) tokenizer
* Supports nested objects * Supports nested objects
* Works with fixed memory allocation : no `malloc()` * Elegant API, very easy to use
* Low footprint * Fixed memory allocation (no malloc)
* Small footprint
* MIT License * MIT License
Example Example
------- -------
char json[] = "{\"Name\":\"Blanchon\",\"Skills\":[\"C\",\"C++\",\"C#\"],\"Age\":32,\"Online\":true}"; char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
JsonParser<32> parser; JsonParser<32> parser;
JsonHashTable hashTable = parser.parseHashTable(json); JsonHashTable root = parser.parseHashTable(json);
if (!hashTable.success()) char* sensor = root.getString("sensor");
{
return;
}
char* name = hashTable.getString("Name"); long time = root.getLong("time");
JsonArray skills = hashTable.getArray("Skills");
int age = hashTable.getLong("Age");
bool online = hashTable.getBool("Online");
JsonArray coords = root.getArray("data");
How to use ? How to use ?
@ -49,14 +42,16 @@ How to use ?
Download the library and extract it to: Download the library and extract it to:
<your Arduino Sketch folder>/libraries/ArduinoJsonParser <your Arduino Sketch folder>/libraries/ArduinoJson
### 2. Import in your sketch ### 2. Import in your sketch
Just add the following line on the top of your `.ino` file: Just add the following lines at the top of your `.ino` file:
#include <JsonParser.h> #include <JsonParser.h>
using namespace ArduinoJson::Parser;
### 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:
@ -233,7 +228,7 @@ Code size
Theses tables has been created by analyzing the map file generated by AVR-GCC after adding `-Wl,-Map,foo.map` to the command line. Theses tables has been created by analyzing the map file generated by AVR-GCC after adding `-Wl,-Map,foo.map` to the command line.
As you'll see the code size if between 1680 and 3528 bytes, depending on the features you use. As you'll see the code size is between 1680 and 3528 bytes, depending on the features you use.
### Minimum setup ### Minimum setup
@ -407,10 +402,3 @@ As you'll see the code size if between 1680 and 3528 bytes, depending on the fea
<td>710</td> <td>710</td>
</tr> </tr>
</table> </table>
Links
-----
* [The project for which I made me this library](http://blog.benoitblanchon.fr/rfid-payment-terminal/)
* [Blog post on the motivation for this library](http://blog.benoitblanchon.fr/arduino-json-parser/)

View File

@ -7,7 +7,8 @@ It's design to be very lightweight, works without any allocation on the heap (no
It has been written with Arduino in mind, but it isn't linked to Arduino libraries so you can use this library in any other C++ project. It has been written with Arduino in mind, but it isn't linked to Arduino libraries so you can use this library in any other C++ project.
# Features Features
--------
* JSON decoding: [more details here](/JsonParser/) * JSON decoding: [more details here](/JsonParser/)
* JSON encoding: [more details here](/JsonGenerator/) * JSON encoding: [more details here](/JsonGenerator/)
@ -16,7 +17,8 @@ It has been written with Arduino in mind, but it isn't linked to Arduino librari
* Small footprint * Small footprint
* MIT License * MIT License
# Feature comparison Feature comparison
------------------
| Library | Memory allocation | Nested objects | Encoding | Parser size | Encoder size | | Library | Memory allocation | Nested objects | Encoding | Parser size | Encoder size |
| ------------ | ----------------- | -------------- | -------- | ----------- | ------------ | | ------------ | ----------------- | -------------- | -------- | ----------- | ------------ |
@ -34,7 +36,8 @@ In each case the target platform was an Arduino Duemilanove and Arduino IDE 1.0.
Links: [json-arduino](https://github.com/not404/json-arduino), [aJson](https://github.com/interactive-matter/aJson) Links: [json-arduino](https://github.com/not404/json-arduino), [aJson](https://github.com/interactive-matter/aJson)
# Testimonials Testimonials
------------
From Arduino's Forum user `jflaplante`: From Arduino's Forum user `jflaplante`:
> I tried the [aJson and json-arduino] before trying your library. I always ran into memory problem after a while. > I tried the [aJson and json-arduino] before trying your library. I always ran into memory problem after a while.
@ -45,3 +48,9 @@ From Arduino's Forum user `gbathree`:
From StackOverflow user `thegreendroid`: From StackOverflow user `thegreendroid`:
> It has a really elegant, simple API and it works like a charm on embedded and Windows/Linux platforms. We recently started using this on an embedded project and I can vouch for its quality. > It has a really elegant, simple API and it works like a charm on embedded and Windows/Linux platforms. We recently started using this on an embedded project and I can vouch for its quality.
Links
-----
* [The project for which I made me this library](http://blog.benoitblanchon.fr/rfid-payment-terminal/)
* [Blog post on the motivation for this library](http://blog.benoitblanchon.fr/arduino-json-parser/)