Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
662 views
in Technique[技术] by (71.8m points)

c++ - Nlohmann json parser crashing while parsing json string

I am using the nlohmann parser to parse a json string, but my code is crashing.

My code

const std::string& dataStr; //I receive dataStr as a parameter, this is just to show type of dataStr
std::string jsonString(dataStr.c_str(), dataStr.c_str() + dataStr.length());
nlohmann::json  jsonData = nlohmann::json::parse(jsonString);

I am getting dataStr as a parameter.

The call stack I am getting is

01  VCRUNTIME140!_CxxThrowException+0x66 [d:srcvctoolscrtvcruntimesrcehhrow.cpp @ 74]
02  !nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer>::parser::unexpect+0x116 [nlohmannjsoninclude
lohmannjson.hpp @ 11619]
03  !nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer>::parser::parse_internal+0x387 [nlohmannjsoninclude
lohmannjson.hpp @ 11584]
04  !nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer>::parser::parse+0x2b [nlohmannjsoninclude
lohmannjson.hpp @ 11387]
05  !nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer>::parse<std::_String_const_iterator<std::_String_val<std::_Simple_types<char> > >,0>+0x7d [
lohmannjsoninclude
lohmannjson.hpp @ 6436]
06  !nlohmann::basic_json<std::map,std::vector,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,bool,__int64,unsigned __int64,double,std::allocator,nlohmann::adl_serializer>::parse<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,0>+0x55 [nlohmannjsoninclude
lohmann*json.hpp* @ 6488]

Error

~ImportsOpen
lohmannjsoninclude
lohmannjson.hpp line 11619, parse error - unexpected.

The error is not reproducible for all jsons, that's why I want to know what does the error mean? Also can it be because the string I am parsing is too big(~20K chars). Any help appreciated, thanks in advance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...