Tencent / rapidjson

A fast JSON parser/generator for C++ with both SAX/DOM style API
http://rapidjson.org/
Other
14.25k stars 3.53k forks source link

Won't read second element in json array #1229

Open CrackerHax opened 6 years ago

CrackerHax commented 6 years ago

The following is valid json: [["stringa","stringb"]]

      string line  = "[[\"stringa\",\"stringb\"]]";
      Document d;
      d.Parse(line.c_str());

      string s1 = d[0].GetString();
      cout<<s1<<endl;
      string s2 = d[1].GetString();
      cout<<s2<<endl;

stringa comes out fine but stringb throws an error

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_M_construct null not valid
miloyip commented 6 years ago

It should be d[0][0].GetString(), d[0][1].GetString(). By the way, it should assert in debug configuration as d[0].IsString() will be false.