EasyManuals Logo

Espressif ESP8266 User Manual

Espressif ESP8266
51 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #43 background imageLoading...
Page #43 background image
C. The JSON Streaming Parser Library
Why would we want to use a streaming parser on the ESP8266? Embedded devices usually
have very limited resources available. One scarce resource is the heap memory. Many of the
REST APIs I am using in my projects provide big response objects, but we are usually just
interested in a small fraction of it. As mentioned earlier, a tree-based parser would load the
whole document into memory and make it available once the document stream has ended.
And this would just crash the ESP8266 pretty quickly; it does not have the resources to keep
200kb on the heap.
This made me port a PHP JSON parser over to C++ and make it available as a library, mostly
to be used in my own projects. Let’s have a look at the header file of the JsonListener:
1
class JsonListener {
2
public:
3
virtual void whitespace(char c) = 0;
4
virtual void startDocument() = 0;
5
virtual void key(String key) = 0;
6
virtual void value(String value) = 0;
7
virtual void endArray() = 0;
8
virtual void endObject() = 0;
9
virtual void endDocument() = 0;
10
virtual void startArray() = 0;
11
virtual void startObject() = 0;
12 };
The methods here are callback methods which will get invoked if the respective event
happens while parsing the document. Let’s start with an example. For the JSON object {“name”:
“Eichhorn”} we get the following invocations:
startDocument(): we start receiving a json document
startObject(): the json object starts with “{“
key(“name”): the parser detected a key object which contains “name”
value(“Eichhorn”): the parser detected a value containing “Eichhorn”
endObject(): the object ends with “}”
endDocument(): the stream of data ends and so does the document
I often just implement (AKA “write code”) for the key() and the value() methods. In the key()
method I store the value of the key parameter. Then later in the value() method I check what

Other manuals for Espressif ESP8266

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Espressif ESP8266 and is the answer not in the manual?

Espressif ESP8266 Specifications

General IconGeneral
Digital I/O Pins17
Analog Input Pins1
Wi-Fi802.11 b/g/n
Operating Voltage3.0V - 3.6V
Clock Speed80 MHz / 160 MHz
Operating Temperature-40°C to 125°C
Dimensions24mm x 14mm
ProcessorTensilica L106 32-bit micro controller

Related product manuals