jsoncpp的使用

1.报abort错误

解决:进入jsoncpp/include/json/assertions.h和config.h

 

//# define JSON_ASSERT(condition) assert(condition)
# define JSON_ASSERT(condition) ;

// The call to assert() will show the failure message in debug builds. In
// release builds we abort, for a core-dump or debugger.
#if 0
# define JSON_FAIL_MESSAGE(message) \
{ \
JSONCPP_OSTRINGSTREAM oss; oss << message; \
assert(false && oss.str().c_str()); \
abort(); \
}
#endif
# define JSON_FAIL_MESSAGE(message) \
{ \
; \
}

#endif

 

#ifndef JSON_USE_EXCEPTION
#define JSON_USE_EXCEPTION 0
#endif

 

2.解析非预期结构体是glibc报free错误

//parse query
std::string query = json_in["cmd_info"]["title4se"].asString();

 json_in["cmd_info"]["title4se"]如果是个object,返回的string会很大。

解决A:

对请求接口解析时,按照要求的格式解析,不符合返回.

 

解决B:

封装一个接口,在调用asxxx的时候判断是否isxxx,比如

asString之前调用isString

posted @ 2017-10-12 11:24  dodng  阅读(463)  评论(0)    收藏  举报