Ask questionsWhen parse a json string, kParseErrorStringEscapeInvalid error will appear, when the value string contains a tab character

My json string a = {"msg":" hello abc","mtime":1596531824} ; There are tabs before the value of msg, and a parse error occurs when document.Parse(a.c_str()) is called

code: rapidjson::Document document; auto errorCode = document.Parse(a.c_str()).GetParseError(); if (errorCode != rapidjson::kParseErrorNone) std::cout<<"json parse failed. errorCode = "<<code<<" ,data = "<<a.c_str()<<std::endl;

will print: json parse failed. errorCode = 10 ,data = {"msg":" hello abc","mtime":1596531824}


Answer questions miloyip

This is a complete and runnable example:

#include "rapidjson/document.h"
#include <iostream>
#include <string>

int main() {
    std::string json = R"({"msg":"\thello abc","mtime":1596531824})";
    rapidjson::Document document;
    auto errorCode = document.Parse(json.c_str()).GetParseError();
    if (errorCode != rapidjson::kParseErrorNone)
        std::cout << "json parse failed. errorCode = "<< errorCode <<" ,data = "<< json.c_str() << std::endl;
        std::cout << document["msg"].GetString() << " " << document["mtime"].GetInt() << std::endl;

On my machine:

$ g++ -I ~/github/rapidjson/include -std=c++11 a.cpp && ./a.out
	hello abc 1596531824

Related questions

是否支持流式解析以及多个json分离解析 hot 1
是否支持流式解析以及多个json分离解析 hot 1
RapidJSON causes cc1plus: internal compiler error: Segmentation fault - rapidjson hot 1
GenericMemberIterator::Iterator implicitly declared private when RAPIDJSON_NOMEMBERITERATORCLASS is defined hot 1
Always gets a core dump while creating json string (rapidjson) hot 1
Bazel Support hot 1
Syntax typo in tutorial hot 1
是否支持流式解析以及多个json分离解析 hot 1
作者你好,我 想请教一下,这个框架是否能够将变量中文stirng 转成wchar_t? 在文档只看到定量 hot 1
travis on windows hot 1
Added headers to my project and got thousands of errors hot 1
Added headers to my project and got thousands of errors hot 1
想要的反斜杠 \. 无法表示,否则JSON解析出错 hot 1
Assertion `stack_.GetSize() == sizeof(ValueType)' failed hot 1
Github User Rank List