Hello,
I want to parse an ifstream containing several JSON objects or arrays, separated by some comment separator lines. So my input is
{ "@format" : "BiBi2013a", "dict" : { "long" : 1, "type" : 3 }, "nbitems" : 2 } ///build 2 [ { "@buid" : 1, "@type" : "itemvector" }, { "@buid" : 3, "@type" : "itemvector" } ]
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) int main (int argc, char**argv) { const char* inpath = argv[1]; std::ifstream ins(inpath,std::ifstream::in); Json::Features jfeatures; jfeatures.allowComments_ = false; jfeatures.strictRoot_ = false; Json::Value jhead; Json::Value jbuild; { Json::Reader readj(jfeatures); if (!readj.parse(ins,jhead)) FATAL("failed to parse header from " << inpath); } DEBUG("tellg " << ins.tellg() << " jhead=" << jhead); unsigned lincnt=0; std::string linstr; 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::Reader readj(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.
Any advices?
Regards.
Basile Starynkevitch http://starynkevitch.net/Basile/
Log in to post a comment.
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/