Skip to content

Bugfix/minor issues fixed #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions JsonStreamingParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void JsonStreamingParser::parse(char c) {
// http://stackoverflow.com/questions/16042274/definition-of-whitespace-in-json
if ((c == ' ' || c == '\t' || c == '\n' || c == '\r')
&& !(state == STATE_IN_STRING || state == STATE_UNICODE || state == STATE_START_ESCAPE
|| state == STATE_IN_NUMBER || state == STATE_START_DOCUMENT)) {
return;
|| state == STATE_IN_NUMBER)) {
return;
}
switch (state) {
case STATE_IN_STRING:
Expand All @@ -68,6 +68,8 @@ void JsonStreamingParser::parse(char c) {
case STATE_IN_ARRAY:
if (c == ']') {
endArray();
} else if (c == '{') {
startObject();
} else {
startValue(c);
}
Expand Down
1 change: 1 addition & 0 deletions examples/ComplexJsonFile/ComplexJsonFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "ComplexJsonFile.h"
28 changes: 28 additions & 0 deletions examples/ComplexJsonFile/ComplexJsonFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "sample.json.h"
#include "JsonStreamingParser.h"
#include "ExampleListener.h"
#include <string.h>

void setup() {
ExampleListener listener = ExampleListener();
JsonStreamingParser parser = JsonStreamingParser();

parser.setListener(&listener);

for (int i = 0; i < strlen(json_sample); i++)
{
parser.parse(json_sample[i]);
}
}

void loop() {

}

#ifndef ARDUINO
int main() {
setup();
loop();
return 0;
}
#endif
1 change: 1 addition & 0 deletions examples/ComplexJsonFile/ComplexJsonFile.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "ComplexJsonFile.h"
47 changes: 47 additions & 0 deletions examples/ComplexJsonFile/ExampleListener.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "ExampleListener.h"
#include "JsonListener.h"


void json_print(String value) {
#ifdef ARDUINO
Serial.println(value.c_str());
#else
printf("%s\n", value.c_str());
#endif
}
void ExampleListener::whitespace(char c) {
json_print("whitespace");
}

void ExampleListener::startDocument() {
json_print("start document");
}

void ExampleListener::key(String key) {
json_print("key: " + key);
}

void ExampleListener::value(String value) {
json_print("value: " + value);
}

void ExampleListener::endArray() {
json_print("end array. ");
}

void ExampleListener::endObject() {
json_print("end object. ");
}

void ExampleListener::endDocument() {
json_print("end document. ");
}

void ExampleListener::startArray() {
json_print("start array. ");
}

void ExampleListener::startObject() {
json_print("start object. ");
}

25 changes: 25 additions & 0 deletions examples/ComplexJsonFile/ExampleListener.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "JsonListener.h"

class ExampleListener: public JsonListener {

public:
virtual void whitespace(char c);

virtual void startDocument();

virtual void key(String key);

virtual void value(String value);

virtual void endArray();

virtual void endObject();

virtual void endDocument();

virtual void startArray();

virtual void startObject();
};
23 changes: 23 additions & 0 deletions examples/ComplexJsonFile/sample.json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const char* json_sample = R"JSON(
{
"simpleValue": 1234,
"simpleFloatValue": 12.345,
"normalizedFloat": 1.345e-6,
"boolean": true,
"string": "str1234",
"arrayOfSimpleValues": [
"text",
6234,
false
],
"arraOfObjects": [
{
"utf8String": "éáőúüóóű",
"escapedString": "\"\u3fd4"
},
{
"whatever": "lol",
"nullValue": null
}
]
})JSON";