Fix parsing empty json object. (#4868)
* Fix parsing empty json object. * Better error message.
This commit is contained in:
@@ -384,8 +384,18 @@ void JsonReader::Error(std::string msg) const {
|
||||
auto end = cursor_.Pos() + kExtend >= raw_str_.size() ?
|
||||
raw_str_.size() : cursor_.Pos() + kExtend;
|
||||
|
||||
std::string const& raw_portion = raw_str_.substr(beg, end - beg);
|
||||
std::string portion;
|
||||
for (auto c : raw_portion) {
|
||||
if (c == '\n') {
|
||||
portion += "\\n";
|
||||
} else {
|
||||
portion += c;
|
||||
}
|
||||
}
|
||||
|
||||
msg += " ";
|
||||
msg += raw_str_.substr(beg, end - beg);
|
||||
msg += portion;
|
||||
msg += '\n';
|
||||
|
||||
msg += " ";
|
||||
@@ -488,9 +498,12 @@ Json JsonReader::ParseArray() {
|
||||
}
|
||||
|
||||
Json JsonReader::ParseObject() {
|
||||
char ch = GetChar('{');
|
||||
GetChar('{');
|
||||
|
||||
std::map<std::string, Json> data;
|
||||
SkipSpaces();
|
||||
char ch = PeekNextChar();
|
||||
|
||||
if (ch == '}') return Json(std::move(data));
|
||||
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user