And I want somehow to parse (outside of JSON, using e.g. the
getline()
function on
std::ifstream
, the separating "comment" (which I don't want to be parsed with JsonCpp) i.e.
///build 2
. Actually, I am generating that JSON file in the same program, so I could replace the
//build 2
with something else e.g.
#build 2
if so wished. However, I really need to parse several JSON values.
I tried without success
#define FATAL(Out) do { i \std::clog<<__FILE__<<":"<<__LINE__\
<<" "<<Out<<";"\
<<std::endl;abort();}while(0)#define DEBUG(Out) do { \std::clog<<__FILE__<<":"<<__LINE__\
<<" "<<Out<<std::endl;}while(0)intmain(intargc,char**argv){constchar*inpath=argv[1];std::ifstreamins(inpath,std::ifstream::in);Json::Featuresjfeatures;jfeatures.allowComments_=false;jfeatures.strictRoot_=false;Json::Valuejhead;Json::Valuejbuild;{Json::Readerreadj(jfeatures);if(!readj.parse(ins,jhead))FATAL("failed to parse header from "<<inpath);}DEBUG("tellg "<<ins.tellg()<<" jhead="<<jhead);unsignedlincnt=0;std::stringlinstr;while(!ins.eof()){linstr.clear();ins.clear();getline(ins,linstr);lincnt++;DEBUG("lincnt="<<lincnt<<" linstr='"<<linstr<<"' empty="<<linstr.empty()<<" eof="<<ins.eof());if(ins.eof())break;if(linstr[0]=='/')break;if(linstr.empty())continue;};{Json::Readerreadj(jfeatures);if(!readj.parse(ins,jbuild))FATAL("failed to parse build from "<<inpath);}DEBUG("jbuild:"<<jbuild);}
and several other variants, but nothing seems to work.
Hello,
I want to parse an ifstream containing several JSON objects or arrays, separated by some comment separator lines. So my input is
And I want somehow to parse (outside of JSON, using e.g. the
function on
, the separating "comment" (which I don't want to be parsed with JsonCpp) i.e.
. Actually, I am generating that JSON file in the same program, so I could replace the
with something else e.g.
if so wished. However, I really need to parse several JSON values.
I tried without success
and several other variants, but nothing seems to work.
Any advices?
Regards.
Basile Starynkevitch http://starynkevitch.net/Basile/