According to the answer Reading a JSON file into ROOT C++
the code bellow works in the interpreter mode and not if I compile it.
$ root -b -q -l testjson.cxx
key: testkey value: testvalue
$ root -b -q -l testjson.cxx+
key: testkey value: testvalue
$ g++ -DMAIN -I`root-config --incdir` testjson.cxx `root-config --libs` -o testjson
$ ./testjson
NULL returned
ROOT version v6-22-06
What am I doing wrong?
Cheers, Rok
#include <stdlib.h>
#include <iostream>
#include <TBufferJSON.h>
struct Example {
std::string key;
std::string value;
};
Example e;
void testjson(){
TString json="{\"_typename\" : \"Example\",\"key\" : \"testkey\",\"value\" : \"testvalue\"}";
auto res = TBufferJSON::FromJSON<Example>(json.Data());
if (!res) std::cout << "NULL returned" << std::endl;
else std::cout << "key: " << res->key << " value: "<< res->value << std::endl;
}
#ifdef MAIN
int main(){testjson();}
#endif