1

I have just installed libjson from sourceforge.net . I tried executing a simple program But i get this error

‘JSONNode’ was not declared in this scope

Here is the code

#include<iostream>

#include <libjson.h>

int main()
{
    JSONNode n(JSON_NODE);
    JSONNode c(JSON_ARRAY);
    c.push_back(JSONNode("", 16));
    c.push_back(JSONNode("", 43));
    c.push_back(JSONNode("", 69));

    n.push_back(c);

    std::string jc = n.write_formatted();
    std::cout<<jc<<std::endl;

    return 0;
}

M I missing some header file ?

Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126

4 Answers4

2

You need to disable #define JSON_LIBRARY in JSONOptions.h, otherwise libjson won't include the C++ headers.

ArtemGr
  • 11,684
  • 3
  • 52
  • 85
1

I see that libjson stuff is defined in the json namespace. Please try adding json:: in front of JSONNode solve the problem? Like this:

json::JSONNode n(JSON_NODE);
json::JSONNode c(JSON_ARRAY);
Lyubomir Vasilev
  • 3,000
  • 17
  • 24
0

You have to make sure to build the libJson library first.

I followed the following thread and it worked great for me after having the same problem you are having:

For running the Make File: http://stackoverflow.com/a/11865407/1399434e

se_brandon
  • 228
  • 10
  • 25
0

disable the JSON_LIBRARY in JSONOptions.h

//#define JSON_LIBRARY

then compile again as below

#include "libjson.h"
using namespace libjson;

int main(int argc, char* argv[])
{

    JSONNode* pNode = NULL;
    return 0;
}
TLama
  • 75,147
  • 17
  • 214
  • 392