So, I might be quite a novice in terms of C++, but still I get to run most libraries just fine.
however this particular library took me ** entirely too long** to compile a first version. I am probably not very qualified to say whether it's because the documentation absolutely blows or is so good that nobody else ever had any questions about it - however from my own experience I gotta say this has pretty much been a nightmare.
OK: so to all novices out there struggling here are some pointers, in order to get this beast of a JSON library running:
int main()
{
std::string json = "{\"RootA\":\"Value in parent node\",\"ChildNode\":{\"ChildA\":\"String Value\",\"ChildB\":42}}";
JSONNode n = libjson::parse(json);
return 0;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2012-06-03
here's a little function that might help you getting started:
#include "libjson.h"
#include <string>
void ParseJSON( JSONNode n){
cout << "starting to parse" << endl;
JSONNode::const_iterator i = n.begin();
while (i != n.end()){
// recursively call ourselves to dig deeper into the tree
if (i -> type() == JSON_ARRAY || i -> type() == JSON_NODE){
ParseJSON(*i);
}
// get the node name and value as a string
std::string node_name = i -> name();
The first couple of sentences in the "Building libjson" section of the documentation explains that you need to uncomment JSON_LIBRARY to use it in C++. Read documentation about building before you try to build it. ;)
The bug in the makefile has already been solved, and the dependencies are now added correctly. This will be fixed in the next version.
If this is your command
g++ json.cc -Llibjson -ljson -I/usr/local/include/libjson
Then you have g++ set up incorrectly. You should not have to include anything in /usr/local/include, that is supposed to be one of g++'s default paths. Try uninstalling and reinstalling g++ using an rpm.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So, I might be quite a novice in terms of C++, but still I get to run most libraries just fine.
however this particular library took me ** entirely too long** to compile a first version. I am probably not very qualified to say whether it's because the documentation absolutely blows or is so good that nobody else ever had any questions about it - however from my own experience I gotta say this has pretty much been a nightmare.
OK: so to all novices out there struggling here are some pointers, in order to get this beast of a JSON library running:
1. edit your JSONOptions.h, it defines what the library is going to look like:
with help from https://sourceforge.net/projects/libjson/forums/forum/1119662/topic/4746879 I adapted mine to the following version.
Use this to get you going:
http://pastebin.com/G7ncxtuX
2. make all
3. you might have some missing depencies, as I did
cp -r ../libjson/Dependencies /usr/local/include/libjson/
or wherever your location is
4. compiling
I ended up with the following commands to my g++ compiler:
g++ json.cc -Llibjson -ljson -I/usr/local/include/libjson
forgot to add:
in your actual code, things should look something like this:
(again thanks to https://sourceforge.net/projects/libjson/forums/forum/1119662/topic/4746879
#include "libjson.h"
#include <string>
int main()
{
std::string json = "{\"RootA\":\"Value in parent node\",\"ChildNode\":{\"ChildA\":\"String Value\",\"ChildB\":42}}";
JSONNode n = libjson::parse(json);
return 0;
}
here's a little function that might help you getting started:
#include "libjson.h"
#include <string>
void ParseJSON( JSONNode n){
cout << "starting to parse" << endl;
JSONNode::const_iterator i = n.begin();
while (i != n.end()){
// recursively call ourselves to dig deeper into the tree
if (i -> type() == JSON_ARRAY || i -> type() == JSON_NODE){
ParseJSON(*i);
}
// get the node name and value as a string
std::string node_name = i -> name();
cout << "name: " << i->name() << " value: " << i->as_string() <<"<br>"<<endl;
++i;
}
}
int main()
{
std::string json = "{\"RootA\":\"Value in parent node\",\"ChildNode\":{\"ChildA\":\"String Value\",\"ChildB\":42}}";
JSONNode node = libjson::parse(json);
ParseJSON(node);
return 0;
}
The first couple of sentences in the "Building libjson" section of the documentation explains that you need to uncomment JSON_LIBRARY to use it in C++. Read documentation about building before you try to build it. ;)
The bug in the makefile has already been solved, and the dependencies are now added correctly. This will be fixed in the next version.
If this is your command
g++ json.cc -Llibjson -ljson -I/usr/local/include/libjson
Then you have g++ set up incorrectly. You should not have to include anything in /usr/local/include, that is supposed to be one of g++'s default paths. Try uninstalling and reinstalling g++ using an rpm.