bblanchon / arduinojson Goto Github PK
View Code? Open in Web Editor NEW📟 JSON library for Arduino and embedded C++. Simple and efficient.
Home Page: https://arduinojson.org
License: MIT License
📟 JSON library for Arduino and embedded C++. Simple and efficient.
Home Page: https://arduinojson.org
License: MIT License
Hello, I am trying to create a list of JSONObject and then interact with the list.
But I found no documentation specific for this use, and to include the item in the list and then remove, could help me with this question?
Hi,
I got the following compile errors when compiling your new API on FreeBSD 10.0 (using clang) :
`Scanning dependencies of target ArduinoJSon
[ 76%] Building CXX object software/extern/json/CMakeFiles/ArduinoJSon.dir/ArduinoJson/src/Arduino/Print.cpp.o
[ 76%] Building CXX object software/extern/json/CMakeFiles/ArduinoJSon.dir/ArduinoJson/src/Internals/IndentedPrint.cpp.o
[ 77%] Building CXX object software/extern/json/CMakeFiles/ArduinoJSon.dir/ArduinoJson/src/Internals/JsonParser.cpp.o
[ 78%] Building CXX object software/extern/json/CMakeFiles/ArduinoJSon.dir/ArduinoJson/src/Internals/List.cpp.o
/opslag/home/oldenburgh/techniek/software/externals/software/extern/json/ArduinoJson/src/Internals/List.cpp:34:16: error: explicit instantiation of 'ArduinoJson::Internals::List' must occur in namespace 'Internals'
template class List;
^
/opslag/home/oldenburgh/techniek/software/externals/software/extern/json/ArduinoJson/src/Internals/../../include/ArduinoJson/Internals/List.hpp:21:7: note: explicit instantiation refers here
class List {
^
/opslag/home/oldenburgh/techniek/software/externals/software/extern/json/ArduinoJson/src/Internals/List.cpp:35:16: error: explicit instantiation of 'ArduinoJson::Internals::List' must occur in namespace 'Internals'
template class List;
^
/opslag/home/oldenburgh/techniek/software/externals/software/extern/json/ArduinoJson/src/Internals/../../include/ArduinoJson/Internals/List.hpp:21:7: note: explicit instantiation refers here
class List {
^
2 errors generated.
software/extern/json/CMakeFiles/ArduinoJSon.dir/build.make:123: recipe for target 'software/extern/json/CMakeFiles/ArduinoJSon.dir/ArduinoJson/src/Internals/List.cpp.o' failed`
Is this a bug, or a compile issue I have?
Hi,
I was wondering if you had any examples of deleting entries from a Generator::JsonObject object. I notice that using add with the same key just appends it to the object.
I get this message after following your instructions, and trying to verify the JsonGeneratorExample:-
JsonGeneratorExample.ino: In function 'void setup()':
JsonGeneratorExample:12: error: 'StaticJsonBuffer' was not declared in this scope
JsonGeneratorExample:12: error: 'jsonBuffer' was not declared in this scope
JsonGeneratorExample:14: error: 'JsonObject' was not declared in this scope
JsonGeneratorExample:14: error: 'root' was not declared in this scope
JsonGeneratorExample:18: error: 'JsonArray' was not declared in this scope
JsonGeneratorExample:18: error: 'data' was not declared in this scope
Similar output for the other two example also.
Please advise.
Folks,
I am now able to use the library on the Galileo and Edison IDE with no problems, however I found a new conflict using it with the <SD.h> library.
see the below error messages.
Looks that is a conflict with: redefinition of 'void* operator new(size_t, void*)
Thanks for the help.
Arduino: 1.5.3-Intel.1.0.4 (Mac OS X), Board: "Intel® Galileo"
In file included from /Users/acasado/Documents/Arduino/libraries/ArduinoJson2master/include/../include/ArduinoJson/Internals/List.hpp:12:0,
from /Users/acasado/Documents/Arduino/libraries/ArduinoJson2master/include/../include/ArduinoJson/JsonArray.hpp:10,
from /Users/acasado/Documents/Arduino/libraries/ArduinoJson2master/include/ArduinoJson.h:8,
from /Users/acasado/Documents/Arduino/libraries/ArduinoJson2master/ArduinoJson.h:7,
from openweathermap.ino:5:
/Users/acasado/Documents/Arduino/libraries/ArduinoJson2master/include/../include/ArduinoJson/Internals/PlacementNew.hpp: In function 'void* operator new(size_t, void_)':
/Users/acasado/Documents/Arduino/libraries/ArduinoJson2master/include/../include/ArduinoJson/Internals/PlacementNew.hpp:13:14: error: redefinition of 'void_ operator new(size_t, void_)'
In file included from /Users/acasado/Desktop/ArduinoEdison.app/Contents/Resources/Java/hardware/tools/x86/i586-poky-linux-uclibc/usr/include/c++/ext/new_allocator.h:34:0,
from /Users/acasado/Desktop/ArduinoEdison.app/Contents/Resources/Java/hardware/tools/x86/i586-poky-linux-uclibc/usr/include/c++/i586-poky-linux-uclibc/bits/c++allocator.h:34,
from /Users/acasado/Desktop/ArduinoEdison.app/Contents/Resources/Java/hardware/tools/x86/i586-poky-linux-uclibc/usr/include/c++/bits/allocator.h:48,
from /Users/acasado/Desktop/ArduinoEdison.app/Contents/Resources/Java/hardware/tools/x86/i586-poky-linux-uclibc/usr/include/c++/string:43,
from /Users/acasado/Desktop/ArduinoEdison.app/Contents/Resources/Java/hardware/arduino/x86/libraries/SD/SD.h:24,
from GALWeather.ino:22:
/Users/acasado/Desktop/ArduinoEdison.app/Contents/Resources/Java/hardware/tools/x86/i586-poky-linux-uclibc/usr/include/c++/new:111:14: error: 'void_ operator new(std::size_t, void*)' previously defined here
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Hi,
On linux, new library doesn't compile.
The file JsonParser.cpp search to include file #include "JsonParser/Jsmn.cpp" but this file is named "JsonParser/jsmn.cpp".
On windows it works because windows is not case sensitive but linux is it.
Best regards.
Hello, I'm using your library in a little project that I'm working on, but I don't know how to use JsonParser and JsonGenerator at the same time... I was hoping that you could help me, so thanks In advance.
Hi again,
Is there an easy way to convert a Parser::JsonObject to Generator::JsonObject? I have a good reason to do this :)
Hi,
when I instruct my compiler (clang++ on FreeBSD10) to be really picky (-Wall -Wpointer-arith -Wswitch -Wreturn-type -Wshadow -Wunused -Werror -Wundef -Wno-ctor-dtor-privacy -Woverloaded-virtual) I get these issues:
[ 79%] Building CXX object software/extern/json/CMakeFiles/ArduinoJSonGenerator.dir/ArduinoJson/JsonGenerator/JsonArrayBase.cpp.o In file included from /opslag/home/oldenburgh/techniek/software/externals/software/extern/json/ArduinoJson/JsonGenerator/JsonArrayBase.cpp:6: /opslag/home/oldenburgh/techniek/software/consoletest/../externals/software/extern/json/ArduinoJson/JsonGenerator/JsonArrayBase.h:18:38: error: declaration shadows a field of 'ArduinoJson::Generator::JsonArrayBase' [-Werror,-Wshadow] JsonArrayBase(JsonValue* items, int capacity) ^ /opslag/home/oldenburgh/techniek/software/consoletest/../externals/software/extern/json/ArduinoJson/JsonGenerator/JsonArrayBase.h:68:24: note: previous declaration is here JsonValue* items;
What is wrong that you call the constructor argument items a name that already exists in the class - this is considered sloppy C++ style 👎 and should be avoided.
Similar things happen here :
[ 78%] Building CXX object software/extern/json/CMakeFiles/ArduinoJSonGenerator.dir/ArduinoJson/JsonGenerator/JsonObjectBase.cpp.o
In file included from /opslag/home/oldenburgh/techniek/software/externals/software/extern/json/ArduinoJson/JsonGenerator/JsonObjectBase.cpp:6:
/opslag/home/oldenburgh/techniek/software/consoletest/../externals/software/extern/json/ArduinoJson/JsonGenerator/JsonObjectBase.h:49:42: error: declaration shadows a field of 'ArduinoJson::Generator::JsonObjectBase' [-Werror,-Wshadow]
JsonObjectBase(KeyValuePair* items, int capacity)
^
/opslag/home/oldenburgh/techniek/software/consoletest/../externals/software/extern/json/ArduinoJson/JsonGenerator/JsonObjectBase.h:55:27: note: previous declaration is here
KeyValuePair* items;
^
/opslag/home/oldenburgh/techniek/software/consoletest/../externals/software/extern/json/ArduinoJson/JsonGenerator/JsonObjectBase.h:49:53: error: declaration shadows a field of 'ArduinoJson::Generator::JsonObjectBase' [-Werror,-Wshadow]
JsonObjectBase(KeyValuePair* items, int capacity)
^
/opslag/home/oldenburgh/techniek/software/consoletest/../externals/software/extern/json/ArduinoJson/JsonGenerator/JsonObjectBase.h:56:17: note: previous declaration is here
int capacity, count;
One could of course turn off the compiler setting "-Wshadow" but I don't think that is the way to go.
If you want to be really scrutinous, on gcc you can include -Weffc++ . This enforces Scott Meyer's "Effective C++ rules". I tried that once but the amount of warnings I got was enormous - so much for writing error-free C++ code !
Benoit, your library is simply awesome: no kidding!
ATM, I'm still in the phase of "assembly" several parts or a small project, originally written in C#, but my knowledge yet experience in C/C++ is close to zero.
https://highfieldtales.wordpress.com/2014/11/07/azure-veneziano-part-1/
More specifically, I'm re-writing the code for the Seeedstudio Link-It, which is an ARM-based board, and comes with a Arduino 1.5-like SDK.
http://www.seeedstudio.com/depot/LinkIt-ONEBackorder-p-2017.html
The problem I bumped to is against your "new" operator definition (PlacementNew.hpp). If I leave it, the compilation raises an error about the re-definition of the "new" operator. If comment out, there's no collision, but your List.cpp module (and another one, I think) raises a overloading not found for the operator "new".
Right now I'm in the office and I don't have the exact errors, but I may send you once at home.
Any clue?
Thanks and have a happy Christmas.
Mario
Bon jour Benoît,
When I construct a JSON array like this :
for (unsigned int i=0;i<5;i++)
{
JsonArray<3> sensorwaarde;
sensorwaarde.add((long int)i);
sensorwaarde.add((i%2==0) ? true : false);
sensorwaarde.add<4>((double)(i*42.34));
}
I explicitly add a floating point value in the 3rd array slot .
However, when I print the resulting strings and process them with wxJSON , I get an error reading the first double, because in the JSON array the 0.0f has (inadvertently) been converted to an integer.
The other values (42.34 .. 169.36) are correctly printed as floats in the array.
15:40:00: json object[0] = {"sensornaam":"Hoogtesensor","waarde":[0,true,0]}
15:40:00: json object[1] = {"sensornaam":"Hoogtesensor","waarde":[1,false,42.34]}
15:40:00: json object[2] = {"sensornaam":"Hoogtesensor","waarde":[2,true,84.68]}
15:40:00: json object[3] = {"sensornaam":"Hoogtesensor","waarde":[3,false,127.02]}
15:40:00: json object[4] = {"sensornaam":"Hoogtesensor","waarde":[4,true,169.36]}
15:40:00: wxJSON parsing[0] : [stand] = 1
/Users/oldenburgh/techniek/software/consoletest/../externals/desktop/wx/wxJSON/jsonval.cpp(907): assert "IsDouble()" failed in AsDouble().
Collecting stack trace information, please wait...
Call stack:
[00] wxJSONValue::AsDouble() const
[01] ConsoleTest::jsonTest() jsonTest.cpp:8
[02] ConsoleTest::MainLoop() main.cpp:5
[03] wxEntry(int&, wchar_t**)
[04] main main.cpp:1
[05] start
[06] 0x00000001
15:40:00: wxJSON parsing[0] : [waarde] = 0.000000
15:40:00: wxJSON parsing[1] : [stand] = 0
15:40:00: wxJSON parsing[1] : [waarde] = 42.340000
15:40:00: wxJSON parsing[2] : [stand] = 1
15:40:00: wxJSON parsing[2] : [waarde] = 84.680000
15:40:00: wxJSON parsing[3] : [stand] = 0
15:40:00: wxJSON parsing[3] : [waarde] = 127.020000
15:40:00: wxJSON parsing[4] : [stand] = 1
15:40:00: wxJSON parsing[4] : [waarde] = 169.360000
15:40:00: Arduino JSON test einde`
I was unable to precisely debug the inner workings of the
void set(double value)
{
printToImpl = &printDoubleTo < DIGITS > ;
content.asDouble = value;
}
function.... Perhaps you could assist me in finding out what goes wrong.
JsonArray output to string is wrong when members are JsonObjects, i get two items (as i inserted 2), but both contain the values of the last added item
JsonObject<3> root;
JsonArray<10> modules;
root.add("paramA", "1234");
root.add("paramB", 1234);
for(int i = 0; i < 2; ++i)
{
JsonObject<3> obj;
obj.add("SParam1", dataArr[i].p1);
obj.add("SParam2", "");
obj.add("SParam3", dataArr[i].p3);
modules.add(obj);
}
root.add("modules", modules);
StringBuilder sbldr(postData, 4096);
sbldr.print(root);
(Disclaimer: I'm not at all an expert in C/C++)
I am trying to build a JsonArray in a for loop on an Arduino Mega 2560, iterating through an array. Here is a (somewhat) minimal example of what I'm trying to do.
struct Person {
int id;
char name[32];
};
Person boss;
boss.id = 1;
strcpy(boss.name, "Jeff");
Person employee;
employee.id = 2;
strcpy(employee.name, "John");
Person persons[2] = {boss, employee};
JsonArray<2> json;
for(int i = 0; i < 2; i++) {
JsonObject<2> object;
object.add("id", persons[i].id);
object.add("name", persons[i].name);
json.add(object);
}
Serial.print(json);
The expected result is:
[
{
id: 1,
name: "Jeff"
},
{
id: 2,
name: "John"
}
]
However, I get this:
[
{
id: 2,
name: "John"
},
{
id: 2,
name: "John"
}
]
Any idea why I can't construct an JsonArray this way?
I'm battling what I'm guessing is a memory issue. In my main loop(), I'm creating a parser then parsing a message. If I create the parser as a 64, I can only send 4 messages successfully and get the proper response before the AVR starts rebooting repeatedly and becomes unresponsive even after reset, requiring power off. If I create the parser as a 16, I can send and respond to more messages, 16. It's as if I need a free() for the parser. I'm relatively new to AVR programming, so perhaps it's something I'm doing.
message being parsed: {"color":[200,0,0],"lednum":4,"msgtype":"ledcolor"}
void loop() {
String msg;
// fetch json message
if(Serial.available()) {
while(1) {
if(Serial.available()) {
char chr = Serial.read();
if (chr == '\r') {
break;
}
msg += chr;
}
}
}
// act on message
if (msg.length() > 0) {
char * cstr = new char [msg.length() + 1];
strcpy(cstr, msg.c_str());
JsonParser<16> parser;
ArduinoJson::Parser::JsonObject incoming = parser.parse(cstr);
if (strcmp(incoming["msgtype"],"ledcolor") == 0) {
ack(1, "got test");
}
}
}
void ack(bool success, char * msg) {
ArduinoJson::Generator::JsonObject<3> outgoing;
outgoing["msgtype"] = "ack";
outgoing["result"] = success;
outgoing["detail"] = msg;
Serial.println(outgoing);
}
Hi,
when I compile the library on FreeBSD 9.2, I get a number of warnings regarding end-of-lines that are missing 👍
[ 76%] Building CXX object software/extern/json/CMakeFiles/ArduinoJSonGenerator.dir/ArduinoJson/JsonGenerator/EscapedString.cpp.o In file included from /home/oldenburgh/techniek/software/externals/software/extern/json/ArduinoJson/JsonGenerator/EscapedString.cpp:6: /home/oldenburgh/techniek/software/externals/software/extern/json/ArduinoJson/JsonGenerator/EscapedString.h:20:2: error: no newline at end of file /home/oldenburgh/techniek/software/externals/software/extern/json/ArduinoJson/JsonGenerator/EscapedString.cpp:45:2: error: no newline at end of file gmake[2]: *** [software/extern/json/CMakeFiles/ArduinoJSonGenerator.dir/ArduinoJson/JsonGenerator/EscapedString.cpp.o] Error 1 gmake[1]: *** [software/extern/json/CMakeFiles/ArduinoJSonGenerator.dir/all] Error 2 gmake: *** [all] Error 2
and
gmake[2]: *** [software/extern/json/CMakeFiles/ArduinoJSonGenerator.dir/ArduinoJson/JsonGenerator/IndentedPrint.cpp.o] Error 1
Would it be possible to check all files to have proper line endings, ie the last statement MUST include a CR at the end and a newline below it. I know on Windows this isn't an issue but on other platforms such as FreeBSD the compiler does not like it.
Hello bblanchon, sorry to open a issue for this.
How can i get the generated json into a string (arduino), i don't want it to serial.
For example i need to output to webserver page.
Using the Arduino IDE 1.0.5, I can't compile the example because of the char[] json
variable. It gives an error: expected unqualified-id before '[' token
If I replace it by char* json
or char json[]
it seems to work.
When compiling in gcc with maximum warning level. it generate only warning:
warning: use of old-style cast [-Wold-style-cast]
return (float)(_content.asDouble);
which can be easely fixed by using a static_cast instead:
--- a/JsonGenerator/JsonValue.h
+++ b/JsonGenerator/JsonValue.h
@@ -76,7 +76,7 @@ namespace ArduinoJson
operator float()
{
- return (float)_content.asDouble;
+ return static_cast<float>(_content.asDouble);
}
operator int()
Hi again,
I was writing some simple parsing tests and came across this error when I ran my test on Valgrind.
Given a test vector like this one -
static const char *jsonSimpleObject = R"*(
{
"firstname": "first",
"lastname": "last"
}
)*";
If I try to get a field that doesn't exist like so -
char *json = strclone( jsonSimpleObject );
JsonHashTable hashTable = parser.parseHashTable( json );
EXPECT_TRUE( hashTable.success() );
EXPECT_THAT( hashTable.getString( "firstname" ), StrEq( "first" ) );
EXPECT_THAT( hashTable.getString( "lastname" ), StrEq( "last" ) );
EXPECT_THAT( hashTable.getString( "middlename" ), Eq( nullptr ) );
The error reported by Valgrind is as below -
==16231== Conditional jump or move depends on uninitialised value(s)
==16231== at 0x81983E5: JsonObjectBase::getNestedTokenCount(jsmntok_t*) (JsonObjectBase.cpp:18)
==16231== by 0x8198253: JsonHashTable::getToken(char const*) (JsonHashTable.cpp:44)
==16231== by 0x81983A5: JsonHashTable::getString(char const*) (JsonHashTable.cpp:83)
==16231== by 0x80EF597:
Hi,
I like to do something like
JsonArray& data = root.createNestedArray("data");
JsonArray& data1 = data.createNestedArray("data1");
data1.add(48.756080, 6);
data1.add(2.302038, 6);
JsonArray& data2 = data.createNestedArray("data2");
data2.add(48.756080, 6);
data2.add(2.302038, 6);
data.add(data1);
data.add(data2);
But get this compilation error
JsonGeneratorExample.ino:19:52: error: no matching function for call to 'ArduinoJson::JsonArray::createNestedArray(const char [6])'
JsonGeneratorExample.ino:19:52: note: candidate is:
In file included from /home/cccc/Arduino_sketchbook/libraries/ArduinoJson/include/ArduinoJson.h:8:0,
from /home/cccc/Arduino_sketchbook/libraries/ArduinoJson/ArduinoJson.h:11,
from JsonGeneratorExample.ino:7:
/home/cccc/Arduino_sketchbook/libraries/ArduinoJson/include/../include/ArduinoJson/JsonArray.hpp:68:14: note: ArduinoJson::JsonArray& ArduinoJson::JsonArray::createNestedArray()
JsonArray &createNestedArray();
My JSON string should look like this {"sensor":"gps","time":1351824120,"data":[[48.756080,2.302038],[48.756080,2.302038]]}
Isn't this possible or where is my error?
Best Christian
I've been watching you consistently develop this library over the past six months, and I used it today for a publish and subscribe architecture designed to help hobbyists move into more advanced robotics. Your library allowed me to implement remote subscription in order to facilitate multi-processor robots.
ArduinoJson saved me a week's worth of time!!
Thank you,
Zac
@zacsketches
It looks like there have been breaking API changes in the latest version of Jsmn.
It'd be great to have this library integrated with the latest version.
It will be perfect if we can find a way to let the size to be dynamic in your Parser and/or Generator :)
I think generator will not be too much tricky compared to parser. Without breaking the code, you can add extra classes that will merge the static allocated objects and arrays.
Here is an example:
JsonObject<2> staticObject1;
JsonObject<1> staticObject2;
staticObject1["key1"] = 1;
staticObject1["key2"] = 2;
staticObject2["key3"] = 3;
DynamicJsonObject dynamicObject;
dynamicObject.merge(staticObject1);
dynamicObject.merge(staticObject2);
Serial.print(dynamicObject);
I installed the ArduinoJson dir into the arduino library and ran the example code and they did not run. Complained about the path. I noticed that the structure is different than other Arduino Libraries. Can you shed some light on this. The documentation on install is not clear.
Thanks in advance
Hi,
I get an error when I try to compile your example code (JsonParserExample.ino) in Sublime text 2 in Linux (Ubuntu 14.04.1). It compiles your code correctly in arduino ide without any errors however in Sublime text 2 I get the following errors, they are related to the tests:
Compiling JsonParserExample...
Creating /home/devicee/Arduino_Build/JsonParserExample/JsonParserExample.ino.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/malloc.c.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/realloc.c.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/CDC.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/HID.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/HardwareSerial.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/IPAddress.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/Print.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/Stream.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/Tone.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/USBCore.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/WInterrupts.c.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/WMath.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/WString.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/main.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/new.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/wiring.c.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/wiring_analog.c.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/wiring_digital.c.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/wiring_pulse.c.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/wiring_shift.c.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/EscapedString.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/IndentedPrint.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/JsonArrayBase.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/JsonObjectBase.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/JsonPrettyPrint.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/JsonPrintable.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/JsonValue.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/Print.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/StringBuilder.cpp.o...
Creating /home/devicee/Arduino_Build/JsonParserExample/EscapedStringTests.cpp.o...
/home/devicee/sketchbook/libraries/ArduinoJson-master/JsonGeneratorTests/EscapedStringTests.cpp:6:25: error: CppUnitTest.h: No such file or directory
/home/devicee/sketchbook/libraries/ArduinoJson-master/JsonGeneratorTests/EscapedStringTests.cpp:10: error: ‘Microsoft’ has not been declared
/home/devicee/sketchbook/libraries/ArduinoJson-master/JsonGeneratorTests/EscapedStringTests.cpp:10: error: ‘CppUnitTestFramework’ is not a namespace-name
/home/devicee/sketchbook/libraries/ArduinoJson-master/JsonGeneratorTests/EscapedStringTests.cpp:10: error: expected namespace-name before ‘;’ token
/home/devicee/sketchbook/libraries/ArduinoJson-master/JsonGeneratorTests/EscapedStringTests.cpp:15: error: expected constructor, destructor, or type conversion before ‘(’ token
/home/devicee/sketchbook/libraries/ArduinoJson-master/JsonGeneratorTests/EscapedStringTests.cpp:95: error: expected `}' at end of input
[Stino - Error 1]
Can you help me to solve this problem? Thank you very much for your support!
So I was attempting to upgrade to the new version and realised that a file is named JsonValue in the parser and the generator.
I know they are in different namespaces but the object file ends up being called JsonValue.o with our build system. Can we not rename them so they don't clash with each other?
Hey Man,
I was trying your json library on Energia. Energia is a child stream of Wiring Arduino.
When I tried to compile the example code JsonParser, I got this error
In file included from C:\Users\def\Downloads\energia-0101E0013-windows\energia-0101E0013\hardware\msp430\libraries\ArduinoJson\JsonParser.cpp:11:0:
C:\Users\def\Downloads\energia-0101E0013-windows\energia-0101E0013\hardware\msp430\libraries\ArduinoJson/JsonParser/JsonValue.cpp: In member function 'ArduinoJson::Parser::JsonValue::operator double()':
C:\Users\def\Downloads\energia-0101E0013-windows\energia-0101E0013\hardware\msp430\libraries\ArduinoJson/JsonParser/JsonValue.cpp:39:47: error: 'strtod' was not declared in this scope
I'm not totally sure if your lib can be reused in any project other than for arduino, but since compilation is on gcc, given that it gets all the files, it should compile clean.
It would be great help to have your library compiled for Energia.
How can we use both generator and parser in the same Arduino sketch without getting namespace conflict errors?
I download the eclipseArduinoIDE from http://www.baeyens.it/eclipse/,
When I verify JsonParserExample.ino in the eclipseArduinoIDE using ArduinoIDE1.5.6-r2 which eclipse insists to,
I get the error:
Starting combiner
"E:/arduino/LinkItOne/arduino-1.5.6-r2/hardware/tools/g++arm_none_eabi/bin/arm-none-eabi-g++" -O2 -Wl,--gc-sections -mcpu=arm7tdmi-s "-T/E:/arduino/LinkItOne/arduino-1.5.6-r2/hardware/arduino/mtk/variants/linkit_one/linker_scripts/gcc/scat.ld" "-Wl,-Map,E:/arduino/LinkItOne/eclipseArduino/workspace/Test/Release/Test.map" -o "E:/arduino/LinkItOne/eclipseArduino/workspace/Test/Release/Test.elf" "-LE:/arduino/LinkItOne/eclipseArduino/workspace/Test/Release" -lm -fpic -msvr4-struct-return -pie -Wl,--entry=gcc_entry -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-unresolved-symbols -Wl,--start-group "E:/arduino/LinkItOne/eclipseArduino/workspace/Test/Release/arduino/syscalls_mtk.c.o" ./.ino.cpp.o ./Libraries/Wire/example/LiquidCrystal_I2C1602V1/LiquidCrystal_I2C.cpp.o ./Libraries/Wire/Wire.cpp.o ./Libraries/Stepper/Stepper.cpp.o ./Libraries/Servo/Servo.cpp.o ./Libraries/SPI/SPI.cpp.o ./Libraries/LWiFi/LWiFi.cpp.o ./Libraries/LWiFi/LWiFiClient.cpp.o ./Libraries/LWiFi/LWiFiServer.cpp.o ./Libraries/LWiFi/LWiFiUdp.cpp.o ./Libraries/LStorage/LFlash.cpp.o ./Libraries/LStorage/LSD.cpp.o ./Libraries/LStorage/LStorage.cpp.o ./Libraries/LGSM/utility/VoiceCall.cpp.o ./Libraries/LGSM/LSMS.cpp.o ./Libraries/LGSM/LVoiceCall.cpp.o ./Libraries/LGPS/utility/GPS.cpp.o ./Libraries/LGPS/LGPS.cpp.o ./Libraries/LGPRS/LGPRS.cpp.o ./Libraries/LGPRS/LGPRSClient.cpp.o ./Libraries/LGPRS/LGPRSServer.cpp.o ./Libraries/LGPRS/LGPRSUdp.cpp.o ./Libraries/LGATT/utility/GATTClient.cpp.o ./Libraries/LGATT/utility/GATTServer.cpp.o ./Libraries/LGATT/LGATTClient.cpp.o ./Libraries/LGATT/LGATTServer.cpp.o ./Libraries/LGATT/LGATTUUID.cpp.o ./Libraries/LEEPROM/utility/sysfile.cpp.o ./Libraries/LEEPROM/LEEPROM.cpp.o ./Libraries/LDateTime/LDateTime.cpp.o ./Libraries/LBattery/utility/Battery.cpp.o ./Libraries/LBattery/LBattery.cpp.o ./Libraries/LBT/utility/BTClient.cpp.o ./Libraries/LBT/utility/BTServer.cpp.o ./Libraries/LBT/LBT.cpp.o ./Libraries/LBT/LBTClient.cpp.o ./Libraries/LBT/LBTServer.cpp.o ./Libraries/LAudio/utility/Audio.cpp.o ./Libraries/LAudio/LAudio.cpp.o ./Libraries/ArduinoJson/src/Internals/IndentedPrint.cpp.o ./Libraries/ArduinoJson/src/Internals/JsonParser.cpp.o ./Libraries/ArduinoJson/src/Internals/List.cpp.o ./Libraries/ArduinoJson/src/Internals/Prettyfier.cpp.o ./Libraries/ArduinoJson/src/Internals/QuotedString.cpp.o ./Libraries/ArduinoJson/src/Internals/StringBuilder.cpp.o ./Libraries/ArduinoJson/src/Arduino/Print.cpp.o ./Libraries/ArduinoJson/src/JsonArray.cpp.o ./Libraries/ArduinoJson/src/JsonBuffer.cpp.o ./Libraries/ArduinoJson/src/JsonObject.cpp.o ./Libraries/ArduinoJson/src/JsonVariant.cpp.o ./Libraries/ArduinoJson/ArduinoJson.cpp.o E:/arduino/LinkItOne/eclipseArduino/workspace/Test/Release/arduino.ar "/E:/arduino/LinkItOne/arduino-1.5.6-r2/hardware/arduino/mtk/variants/linkit_one/libmtk.a" "E:/arduino/LinkItOne/eclipseArduino/workspace/Test/Release/arduino.ar" -Wl,--end-group
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::IndentedPrint::write(unsigned char)': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/IndentedPrint.cpp:11: multiple definition of
ArduinoJson::Internals::IndentedPrint::write(unsigned char)'
./Libraries/ArduinoJson/src/Internals/IndentedPrint.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/IndentedPrint.cpp:11: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::JsonParser::skip(char const*)': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:32: multiple definition of
ArduinoJson::Internals::JsonParser::skip(char const)'
./Libraries/ArduinoJson/src/Internals/JsonParser.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:32: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::QuotedString::extractFrom(char_, char**)': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/QuotedString.cpp:60: multiple definition of
ArduinoJson::Internals::QuotedString::extractFrom(char*, char**)'
./Libraries/ArduinoJson/src/Internals/QuotedString.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/QuotedString.cpp:60: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::StringBuilder::write(unsigned char)': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/StringBuilder.cpp:11: multiple definition of
ArduinoJson::Internals::StringBuilder::write(unsigned char)'
./Libraries/ArduinoJson/src/Internals/StringBuilder.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/StringBuilder.cpp:11: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonArray::at(int) const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonArray.cpp:17: multiple definition of
ArduinoJson::JsonArray::at(int) const'
./Libraries/ArduinoJson/src/JsonArray.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonArray.cpp:17: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonBuffer::createArray()': E:/arduino/workspace/libraries/ArduinoJson/src/JsonBuffer.cpp:16: multiple definition of
ArduinoJson::JsonBuffer::createArray()'
./Libraries/ArduinoJson/src/JsonBuffer.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonBuffer.cpp:16: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonBuffer::createObject()': E:/arduino/workspace/libraries/ArduinoJson/src/JsonBuffer.cpp:21: multiple definition of
ArduinoJson::JsonBuffer::createObject()'
./Libraries/ArduinoJson/src/JsonBuffer.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonBuffer.cpp:21: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonVariant::operator ArduinoJson::JsonArray&() const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:17: multiple definition of
ArduinoJson::JsonVariant::operator ArduinoJson::JsonArray&() const'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:17: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonVariant::operator ArduinoJson::JsonObject&() const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:21: multiple definition of
ArduinoJson::JsonVariant::operator ArduinoJson::JsonObject&() const'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:21: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonVariant::operator bool() const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:25: multiple definition of
ArduinoJson::JsonVariant::operator bool() const'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:25: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonVariant::operator char const*() const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:29: multiple definition of
ArduinoJson::JsonVariant::operator char const_() const'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:29: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonVariant::operator double() const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:33: multiple definition of
ArduinoJson::JsonVariant::operator double() const'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:33: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonVariant::operator long() const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:37: multiple definition of
ArduinoJson::JsonVariant::operator long() const'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:37: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonVariant::set(bool)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:41: multiple definition of
ArduinoJson::JsonVariant::set(bool)'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:41: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonVariant::set(char const_)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:47: multiple definition of
ArduinoJson::JsonVariant::set(char const*)'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:47: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::JsonVariant::set(double, unsigned char)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:53: multiple definition of
ArduinoJson::JsonVariant::set(double, unsigned char)'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:53: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::JsonVariant::set(long)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:59: multiple definition of
ArduinoJson::JsonVariant::set(long)'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:59: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::JsonVariant::set(ArduinoJson::JsonArray&)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:65: multiple definition of
ArduinoJson::JsonVariant::set(ArduinoJson::JsonArray&)'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:65: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::JsonVariant::set(ArduinoJson::JsonObject&)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:71: multiple definition of
ArduinoJson::JsonVariant::set(ArduinoJson::JsonObject&)'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:71: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::JsonVariant::size() const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:77: multiple definition of
ArduinoJson::JsonVariant::size() const'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:77: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::JsonVariant::operator[](int)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:83: multiple definition of
ArduinoJson::JsonVariant::operator'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:83: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::Internals::QuotedString::printTo(char const_, Print&)': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/QuotedString.cpp:34: multiple definition of
ArduinoJson::Internals::QuotedString::printTo(char const_, Print&)'
./Libraries/ArduinoJson/src/Internals/QuotedString.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/QuotedString.cpp:34: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonObject::getNodeAt(char const*) const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:62: multiple definition of
ArduinoJson::JsonObject::getNodeAt(char const_) const'
./Libraries/ArduinoJson/src/JsonObject.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:62: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonObject::remove(char const_)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:46: multiple definition of
ArduinoJson::JsonObject::remove(char const*)'
./Libraries/ArduinoJson/src/JsonObject.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:46: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::JsonObject::operator[](char const*)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:30: multiple definition of
ArduinoJson::JsonObject::operator[](char const*)'
./Libraries/ArduinoJson/src/JsonObject.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:30: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::JsonVariant::operator[](char const*)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:88: multiple definition of
ArduinoJson::JsonVariant::operator[](char const*)'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:88: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::JsonObject::createNestedObject(char const_)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:55: multiple definition of
ArduinoJson::JsonObject::createNestedObject(char const_)'
./Libraries/ArduinoJson/src/JsonObject.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:55: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonObject::createNestedArray(char const*)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:48: multiple definition of
ArduinoJson::JsonObject::createNestedArray(char const_)'
./Libraries/ArduinoJson/src/JsonObject.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:48: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonObject::at(char const_) const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:25: multiple definition of
ArduinoJson::JsonObject::at(char const*) const'
./Libraries/ArduinoJson/src/JsonObject.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:25: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::JsonObject::at(char const_)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:20: multiple definition of
ArduinoJson::JsonObject::at(char const_)'
./Libraries/ArduinoJson/src/JsonObject.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:20: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::Prettyfier::unindentIfNeeded()': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/Prettyfier.cpp:81: multiple definition of
ArduinoJson::Internals::Prettyfier::unindentIfNeeded()'
./Libraries/ArduinoJson/src/Internals/Prettyfier.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/Prettyfier.cpp:81: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::Prettyfier::indentIfNeeded()': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/Prettyfier.cpp:74: multiple definition of
ArduinoJson::Internals::Prettyfier::indentIfNeeded()'
./Libraries/ArduinoJson/src/Internals/Prettyfier.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/Prettyfier.cpp:74: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::Prettyfier::write(unsigned char)': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/Prettyfier.cpp:11: multiple definition of
ArduinoJson::Internals::Prettyfier::write(unsigned char)'
./Libraries/ArduinoJson/src/Internals/Prettyfier.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/Prettyfier.cpp:11: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::JsonParser::skipSpaces()': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:20: multiple definition of
ArduinoJson::Internals::JsonParser::skipSpaces()'
./Libraries/ArduinoJson/src/Internals/JsonParser.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:20: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::JsonParser::skip(char)': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:24: multiple definition of
ArduinoJson::Internals::JsonParser::skip(char)'
./Libraries/ArduinoJson/src/Internals/JsonParser.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:24: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonObject::writeTo(ArduinoJson::Internals::JsonWriter&) const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:69: multiple definition of
ArduinoJson::JsonObject::writeTo(ArduinoJson::Internals::JsonWriter&) const'
./Libraries/ArduinoJson/src/JsonObject.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonObject.cpp:69: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonVariant::writeTo(ArduinoJson::Internals::JsonWriter&) const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:93: multiple definition of
ArduinoJson::JsonVariant::writeTo(ArduinoJson::Internals::JsonWriter&) const'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:93: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonArray::writeTo(ArduinoJson::Internals::JsonWriter&) const': E:/arduino/workspace/libraries/ArduinoJson/src/JsonArray.cpp:46: multiple definition of
ArduinoJson::JsonArray::writeTo(ArduinoJson::Internals::JsonWriter&) const'
./Libraries/ArduinoJson/src/JsonArray.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonArray.cpp:46: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonArray::add()': E:/arduino/workspace/libraries/ArduinoJson/src/JsonArray.cpp:23: multiple definition of
ArduinoJson::JsonArray::add()'
./Libraries/ArduinoJson/src/JsonArray.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonArray.cpp:23: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonArray::createNestedObject()': E:/arduino/workspace/libraries/ArduinoJson/src/JsonArray.cpp:39: multiple definition of
ArduinoJson::JsonArray::createNestedObject()'
./Libraries/ArduinoJson/src/JsonArray.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonArray.cpp:39: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonArray::createNestedArray()': E:/arduino/workspace/libraries/ArduinoJson/src/JsonArray.cpp:32: multiple definition of
ArduinoJson::JsonArray::createNestedArray()'
./Libraries/ArduinoJson/src/JsonArray.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonArray.cpp:32: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::JsonParser::parseArray()': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:89: multiple definition of
ArduinoJson::Internals::JsonParser::parseArray()'
./Libraries/ArduinoJson/src/Internals/JsonParser.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:89: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::JsonParser::parseAnythingTo(ArduinoJson::JsonVariant&)': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:41: multiple definition of
ArduinoJson::Internals::JsonParser::parseAnythingTo(ArduinoJson::JsonVariant&)'
./Libraries/ArduinoJson/src/Internals/JsonParser.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:41: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonBuffer::parseArray(char*, unsigned char)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonBuffer.cpp:26: multiple definition of
ArduinoJson::JsonBuffer::parseArray(char_, unsigned char)'
./Libraries/ArduinoJson/src/JsonBuffer.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonBuffer.cpp:26: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::Internals::JsonParser::parseObject()': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:119: multiple definition of
ArduinoJson::Internals::JsonParser::parseObject()'
./Libraries/ArduinoJson/src/Internals/JsonParser.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/Internals/JsonParser.cpp:119: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function ArduinoJson::JsonBuffer::parseObject(char_, unsigned char)': E:/arduino/workspace/libraries/ArduinoJson/src/JsonBuffer.cpp:31: multiple definition of
ArduinoJson::JsonBuffer::parseObject(char*, unsigned char)'
./Libraries/ArduinoJson/src/JsonBuffer.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonBuffer.cpp:31: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::Internals::IndentedPrint::writeTabs()': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/../../include/ArduinoJson/Internals/List.hpp:60: multiple definition of
ArduinoJson::JsonArray::_invalid'
./Libraries/ArduinoJson/src/JsonArray.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonArray.cpp:17: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In functionArduinoJson::Internals::IndentedPrint::writeTabs()': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/../../include/ArduinoJson/Internals/ListNode.hpp:20: multiple definition of
ArduinoJson::JsonObject::_invalid'
./Libraries/ArduinoJson/src/JsonObject.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/../include/ArduinoJson/Internals/List.hpp:32: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o: In function.LANCHOR1': E:/arduino/workspace/libraries/ArduinoJson/src/Internals/IndentedPrint.cpp:11: multiple definition of
ArduinoJson::JsonVariant::_invalid'
./Libraries/ArduinoJson/src/JsonVariant.cpp.o:E:/arduino/workspace/libraries/ArduinoJson/src/JsonVariant.cpp:17: first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o:(.data.rel.ro+0x0): multiple definition ofvtable for ArduinoJson::Internals::StringBuilder' ./Libraries/ArduinoJson/src/Internals/StringBuilder.cpp.o:(.data.rel.ro+0x0): first defined here ./Libraries/ArduinoJson/ArduinoJson.cpp.o:(.data.rel.ro+0x10): multiple definition of
vtable for ArduinoJson::Internals::Prettyfier'
./Libraries/ArduinoJson/src/Internals/Prettyfier.cpp.o:(.data.rel.ro+0x0): first defined here
./Libraries/ArduinoJson/ArduinoJson.cpp.o:(.data.rel.ro+0x20): multiple definition of`vtable for ArduinoJson::Internals::IndentedPrint'
./Libraries/ArduinoJson/src/Internals/IndentedPrint.cpp.o:(.data.rel.ro+0x0): first defined here
collect2: ld returned 1 exit status
Only the ArduinoJson will be error. help.....
Hi,
Great Plugin, but i need to send the Json package via I2c and before it i want to copy in a buffer of 32Bytes, Do you have some idea of how use your library for that?
thanks
Hi again,
At the moment, the library only supports a single non-portable unsigned type (long) and double.
long time = root["time"];
jsonObject["time" = (long)time; // If time is a uint32_t
Would it be possible to add support for C99 types (e.g. uint8_t, uint16_t, uint32_t, int8_t and float etc.) for accessing and setting JSON values? This would get rid of a lot of unnecessary casts in codebases that use C99 types like ours.
uint32_t time = root["time"];
jsonObject["time"] = time;
Thanks!
I modified the JsonParserExample to call a function do do the parsing
Setup just sets baudrate
loop calls a function that passes in the json char array the parse function runs then delays for 10 seconds
the first 3 times thru the loop it appears all ok, 4 and onward times thru the loop the prse function reports parse Object fail
I can provide test sketch but don't see how to add the attachment to this new issue post
Hi,
The pragma you entered suppresses the virtual destructor warning in the static buffer declaration.
I have another issue, this time with the dynamic buffer, with not declaring the destructor virtual :
[ 94%] Building CXX object toepassing/usb/CMakeFiles/stm32f3demo.elf.dir/usb_bot.cpp.o In file in cluded from /Users/oldenburgh/techniek/Variosystem/software/boardtest/torenvalk/../../externals/software/extern/json/ArduinoJson/include/ArduinoJson.h:7:0, from /Users/oldenburgh/techniek/Variosystem/software/boardtest/torenvalk/toepassing/usb/h/usbdemo.h:22, from /Users/oldenburgh/techniek/Variosystem/software/boardtest/torenvalk/toepassing/usb/usb_bot.cpp:38: /Users/oldenburgh/techniek/Variosystem/software/boardtest/torenvalk/../../externals/software/extern/json/ArduinoJson/include/../include/ArduinoJson/DynamicJsonBuffer.hpp: In destructor 'ArduinoJson::DynamicJsonBuffer::~DynamicJsonBuffer()': /Users/oldenburgh/techniek/Variosystem/software/boardtest/torenvalk/../../externals/software/extern/json/ArduinoJson/include/../include/ArduinoJson/DynamicJsonBuffer.hpp:20:33: error: deleting object of polymorphic class type 'ArduinoJson::DynamicJsonBuffer' which has non-virtual destructor might cause undefined behaviour [-Werror=delete-non-virtual-dtor] ~DynamicJsonBuffer() { delete _next; } ^ cc1plus: all warnings being treated as errors
This time, it concerns the dynamic buffer constructor. I see no issue here to declare it virtual, since this class assumes using dynamic allocation anyway.
(The compiler warning shown here originates from arm-none-eabi-g++ 4.8.4 )
Something like this -
for ( auto i = jsonHashTable.begin(), i != jsonHashTable.end(); i++ ) {
cout << "Key " << i->first;
cout << "Value" << i->second;
}
for ( auto i = jsonArray.begin(), i != jsonArray.end(); i++ ) {
cout << "Value" << *i;
}
I think this will involve writing a custom iterator (see http://www.cplusplus.com/reference/iterator/) for these two classes, hopefully it isn't too difficult.
When compiling for STM32 Cortex-M4 I got this warning 👎:
ArduinoJson/src/Internals/../../include/ArduinoJson/Internals/../JsonBuffer.hpp:21:7: error: 'class ArduinoJson::JsonBuffer' has virtual functions and accessible non-virtual destructor [-Werror=non-virtual-dtor] class JsonBuffer { ^ cc1plus: all warnings being treated as errors
I saw the comment about adding malloc() to Arduino code. This is quite true, but leaving a destructor not virtual with virtual functions is considered very sloppy programming.
😄 I propose you add #ifndef ARDUINO
around the virtual destructor. On my STM32 those 500 bytes are of no concern and I would like to get rid of the compiler warning, which translates into an error in my build.
though the Arduino IDE itself works very well and great, using Eclipse with Baeyens Arduino Plugin seens to handle imports or paths different.
Would mind you check http://forum.arduino.cc/index.php?topic=263011.0 for further details?
thanks & cheers for this great lib
Is there a reliable method of checking to see if the JSON data contains a given key? The methods I'm trying are all failing horribly and I'm sure it's my fault.
compiling the IndentedPrintExample the compiler raises:
IndentedPrintExample.cpp.o: In function setup': IndentedPrintExample.cpp:(.text.setup+0x16): undefined reference to
vtable for ArduinoJson::Internals::IndentedPrint'
#include <ArduinoJson.h>
void setup() {
Serial.begin(9600);
delay(2000);
StaticJsonBuffer<200> jsonBuffer;
char json[] =
"{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[{\"a\":48.756080,\"b\":2.302038}]}";
JsonObject& root = jsonBuffer.parseObject(json);
if (!root.success()) {
Serial.println("parseObject() failed");
return;
}
const char* sensor = root["sensor"];
long time = root["time"];
JsonArray& array = root["data"];
Serial.println(sensor);
Serial.println(time);
Serial.println(array.size());
}
void loop() {
// not used in this example
}
array.size() is 0.
It seems parse fail,but no error occur.
I want to send a JSON string via UDP from my Arduino. I was thinking to use this method (from the wiki):
char buffer[256];
array.printTo(buffer, sizeof(buffer));
I would prefer not to allocate such a large buffer. Is there a way to get the length of the string that will be generated so the buffer can be sized accordingly? Example code that could do with these improvements:
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["sensor"] = "gps";
root["time"] = 1351824120;
JsonArray& data = root.createNestedArray("data");
data.add(48.756080, 6); // 6 is the number of decimals to print
data.add(2.302038, 6); // if not specified, 2 digits are printed
char buffer[256];
root.printTo(buffer, sizeof(buffer));
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(remoteIP, port);
Udp.write(buffer, sizeof(buffer));
Udp.endPacket();
The current version of the library ArduinoJson V4 is not visible on the MAC when used from the ARDUINO IDE used by Arduino Galileo and Arduino Edison, the IDE provided by INTEL Arduino 1.5.3-Intel 1.0.4 https://communities.intel.com/docs/DOC-23242
If we delete the file "libraries.properties" from the library, the IDE sees the library, however it has compile errors.
I had no problems when used on the MAC with Arduino IDE 1.5.6-r2
The implementation is really elegant indeed.
I am using it to parse the weather from openweathermap.org on the JSON format API.
Thanks.
AC/.
I experience a wrong serialization by using such a snippet:
//
// Step 1: Reserve memory space
//
StaticJsonBuffer<200> jsonBuffer;
//
// Step 2: Build object tree in memory
//
JsonObject& root = jsonBuffer.createObject();
root["sensor"] = "gps";
root["time"] = 1351824120;
JsonArray& data = root.createNestedArray("data");
//data.add(48.756080, 6); // 6 is the number of decimals to print
//data.add(2.302038, 6); // if not specified, 2 digits are printed
{
JsonObject& jsens = data.createNestedObject();
jsens["name"] = "tizio";
jsens["value"] = true;
}
{
JsonObject& jsens = data.createNestedObject();
jsens["name"] = "caio";
jsens["value"] = 3.141519;
}
//
// Step 3: Generate the JSON string
//
root.printTo(Serial);
The resulting JSON is the following:
{"sensor":"gps","time":1351824120,"data":[{"name":"tizio"}]}
Is it me?
Hi,
how are the number of tokens calculated?
Following the example I got:
char json[] = "{"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}";
1 token = sensor
2 token = gps
3 token = time
4 token = 1351824120
5 token = data
6 token = [48.756080,2.302038] the array itself
7 token = 48.756080
8 token = 2.302038
9 token = the whole object
How do you get 12 tokens?
Trying to send the JSON data using the Arduino Ethernet library.
Is this possible with the library you have written?
If so could you provide a small example?
Hi,
I tried building your nice library with arm-none-eabi-g++ for ST STM32. I got into problems because my compiler did not know size_t in Print.h .
My fix : I included this :
before
After that, it build without problems.
You have written a great library, thank you so much! Your code in version 4 looks really clean, I am impressed. It seems that now the JSON parser only operates in what you were calling strict-mode in your previous version. Now if the JSON is not well formed it returns an error instead of parsing in a non-strict manor. Would you consider replacing the original non-strict parsing behavior? Perhaps that would ruin the cleanliness of your new code and it is not reasonable to expect a JSON parser to handle ill formed strings, but I did think it was really nice when your previous code gracefully accepted what now it simply rejects. Previously it seemed that strings inside the JSON did not necessarily need quotation marks, and tokens could be separated with spaces as well as commas. Perhaps even more was allowed through the old non-strict parser that other more strict parsers would reject. I am using your library to parse JSON that I type on a command line and your previous non-strict version saved me from having to type lots of characters that I now need to add. Perhaps I am being lazy and sloppy, but would you please consider restoring the old behavior, at least as an option?
I have just started using your library (great, easy-to-use library by the way!) and I was wondering if it would be possible to implement JSON encoding as well.
At the moment, we have to hand-code outbound JSON (which is slightly painful and error-prone).
Hello again,
Say if we were to parse JSON that looked like this -
{
"message": "\"Hello there\""
}
When we read it out like so -
JsonObject root = parser->parse( json );
const char *message = root["message"];
// Shouldn't we be getting the unescaped form here?
I noticed that we still get the escaped form. Perhaps this is a bug in Jsmn?
variable name shadowing occurs :
In file included from /Users/oldenburgh/techniek/software/consoletest/../externals/software/extern/json/ArduinoJson/include/ArduinoJson.h:10, from /Users/oldenburgh/techniek/software/consoletest/toepassing/jsonTest.cpp:17: /Users/oldenburgh/techniek/software/consoletest/../externals/software/extern/json/ArduinoJson/include/../include/ArduinoJson/StaticJsonBuffer.hpp: In member function ‘virtual void* ArduinoJson::StaticJsonBuffer<CAPACITY>::alloc(size_t)’: /Users/oldenburgh/techniek/software/consoletest/../externals/software/extern/json/ArduinoJson/include/../include/ArduinoJson/StaticJsonBuffer.hpp:25: warning: declaration of ‘size’ shadows a member of 'this'
Do you have a plan about indentation of printed/generated string?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.