本文整理汇总了C++中rapidjson::Document::HasParseError方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::HasParseError方法的具体用法?C++ Document::HasParseError怎么用?C++ Document::HasParseError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rapidjson::Document
的用法示例。
在下文中一共展示了Document::HasParseError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create
static elliptics_client_state create(const std::string &conf, rapidjson::Document &doc) {
FILE *cf;
cf = fopen(conf.c_str(), "r");
if (!cf) {
std::ostringstream str;
str << "failed to open config file '" << conf << "'";
throw configuration_error(str.str().c_str());
}
try {
rapidjson::FileStream fs(cf);
doc.ParseStream<rapidjson::kParseDefaultFlags, rapidjson::UTF8<>, rapidjson::FileStream>(fs);
if (doc.HasParseError()) {
std::ostringstream str;
str << "can not parse config file '" << conf << "': " << doc.GetParseError();
throw configuration_error(str.str().c_str());
}
fclose(cf);
cf = NULL;
return create(doc);
} catch (...) {
if (cf)
fclose(cf);
throw;
}
}
示例2: GetFaceInfo
int ytopen_sdk::GetFaceInfo(rapidjson::Document &result, const string&face_id)
{
std::stringstream ss;
ss<<host<<"/youtu/api/getfaceinfo";
string addr;
addr.assign(ss.str());
string req;
string rsp;
StringBuffer sbuffer;
Writer<StringBuffer> writer(sbuffer);
writer.StartObject();
writer.String("app_id");writer.String(app_id.c_str());
writer.String("face_id");writer.String(face_id.c_str());
writer.EndObject();
req = sbuffer.GetString();
int ret = curl_method(addr, req, rsp);
if(ret == 0) {
result.Parse<rapidjson::kParseStopWhenDoneFlag>(rsp.c_str());
if(result.HasParseError()) {
std::cout << "RapidJson parse error " << result.GetParseError() << endl;
return -1;
}
}else {
return -1;
}
return 0;
}
示例3: parse_file
bool parse_file(rapidjson::Document & doc, std::string const& file_name)
{
file_string file_data(file_name);
if(file_data.is_valid() == false)
{
log_error(log_scope::ENGINE,
"Unable to open json file \"{}\".", file_name);
return false;
}
doc.Parse<0>(file_data.get_str().c_str());
if(doc.HasParseError())
{
// rapidjson does not provide line/column, only character offset
// hacking it here until (if) rapidjson implements it
std::string const& file_data_str = file_data.get_str();
size_t const error_char_offset = doc.GetErrorOffset();
std::string::const_iterator error_it =
file_data_str.cbegin() + error_char_offset;
// Compute line number, using 1 as base line
size_t const error_line_num = 1 + std::count_if(
file_data_str.cbegin(),
error_it,
std::bind2nd(std::equal_to<char>(), '\n'));
// Compute column (char offset into line), using 1 as base column
std::string::const_reverse_iterator reverse_error_it{error_it};
auto error_line_begin_it = std::find(
reverse_error_it,
file_data_str.crend(),
'\n');
// If this is the first line we can
size_t const error_column_num =
error_line_begin_it != file_data_str.crend()
? std::distance(reverse_error_it, error_line_begin_it) + 1
: error_char_offset + 1;
// Log error
log_error(log_scope::ENGINE, "Error parsing json file {}", file_name);
log_error_no_prefix(log_line_seperator);
log_error_no_prefix("== JSON ERRORS ==========");
log_error_no_prefix("Line {}, Column {} - {}",
error_line_num,
error_column_num,
doc.GetParseError());
log_error_no_prefix(log_line_seperator);
return false;
}
return true;
}
示例4: readJson
bool ComRender::readJson(const std::string &fileName, rapidjson::Document &doc)
{
bool ret = false;
do {
std::string contentStr = FileUtils::getInstance()->getStringFromFile(fileName);
doc.Parse<0>(contentStr.c_str());
CC_BREAK_IF(doc.HasParseError());
ret = true;
} while (0);
return ret;
}
示例5: parseJson
bool parseJson(const char* json,rapidjson::Document& doc){
doc.Parse<0>(json);
if(doc.HasParseError()){
rapidjson::ParseErrorCode e = doc.GetParseError();
size_t o = doc.GetErrorOffset();
std::cerr << "Error: " << rapidjson::GetParseError_En(e) << std::endl;;
std::string slice = (strlen(json)>o+10)?std::string(json).substr(o,10):std::string(json);
std::cerr << " at offset " << o << " near '" << slice << "...'" << std::endl;
return false;
}
return true;
}
示例6: readJson
bool SceneReader::readJson(const std::string &fileName, rapidjson::Document &doc)
{
bool bRet = false;
do {
std::string jsonpath = FileUtils::getInstance()->fullPathForFilename(fileName);
std::string contentStr = FileUtils::getInstance()->getStringFromFile(jsonpath);
doc.Parse<0>(contentStr.c_str());
CC_BREAK_IF(doc.HasParseError());
bRet = true;
} while (0);
return bRet;
}
示例7: NewPerson
int ytopen_sdk::NewPerson(rapidjson::Document &result, const string& person_id, const string &person_name, const std::vector<string> &group_ids, const string& imagePath, int data_type, const string &tag)
{
string imageData;
if(data_type == 0 && 0 != read_image(imagePath, imageData)) {
cout << "image read failed. " << imagePath << endl;
return -1;
}
std::stringstream ss;
ss<<host<<"/youtu/api/newperson";
string addr;
addr.assign(ss.str());
string req;
string rsp;
StringBuffer sbuffer;
Writer<StringBuffer> writer(sbuffer);
writer.StartObject();
writer.String("app_id"); writer.String(app_id.c_str());
if(data_type == 0) {
string encode_data = b64_encode(imageData);
writer.String("image"); writer.String(encode_data.c_str());
}else {
writer.String("url"); writer.String(imagePath.c_str());
}
writer.String("person_id"); writer.String(person_id.c_str());
writer.String("person_name"); writer.String(person_name.c_str());
writer.String("group_ids");
writer.StartArray();
for(int i = 0; i < group_ids.size(); i++)
writer.String(group_ids[i].c_str());
writer.EndArray();
writer.String("tag"); writer.String(tag.c_str());
writer.EndObject();
req = sbuffer.GetString();
int ret = curl_method(addr, req, rsp);
if(ret == 0) {
result.Parse<rapidjson::kParseStopWhenDoneFlag>(rsp.c_str());
if(result.HasParseError()) {
std::cout << "RapidJson parse error " << result.GetParseError() << endl;
return -1;
}
}else {
return -1;
}
return 0;
}
示例8: FaceCompare
int ytopen_sdk::FaceCompare(rapidjson::Document &result, const string& imagePathA, const string&imagePathB, int data_type)
{
result.SetNull();
string imageA, imageB;
if(data_type == 0 &&
(0 != read_image(imagePathA, imageA) || 0 != read_image(imagePathB, imageB))) {
cout << "image read failed. " << imagePathA << "," << imagePathB << endl;
return -1;
}
std::stringstream ss;
ss<<host<<"/youtu/api/facecompare";
string addr;
addr.assign(ss.str());
string req;
string rsp;
StringBuffer sbuffer;
Writer<StringBuffer> writer(sbuffer);
writer.StartObject();
writer.String("app_id"); writer.String(app_id.c_str());
if(data_type == 0) {
string encode_data = b64_encode(imageA);
writer.String("imageA"); writer.String(encode_data.c_str());
encode_data = b64_encode(imageB);
writer.String("imageB"); writer.String(encode_data.c_str());
}else {
writer.String("urlA"); writer.String(imagePathA.c_str());
writer.String("urlB"); writer.String(imagePathB.c_str());
}
writer.EndObject();
req = sbuffer.GetString();
int ret = curl_method(addr, req, rsp);
if(ret == 0) {
result.Parse<rapidjson::kParseStopWhenDoneFlag>(rsp.c_str());
if(result.HasParseError()) {
std::cout << "RapidJson parse error " << result.GetParseError() << endl;
return -1;
}
}else {
return -1;
}
return 0;
}
示例9: ImageTag
int ytopen_sdk::ImageTag(rapidjson::Document &result, const std::string &imagePath, int data_type, const string &cookie)
{
string imageData;
if(data_type == 0 && 0 != read_image(imagePath, imageData)) {
cout << "image read failed. " << imagePath << endl;
return -1;
}
std::stringstream ss;
ss<<host<<"/youtu/imageapi/imagetag";
string addr;
addr.assign(ss.str());
string req;
string rsp;
StringBuffer sbuffer;
Writer<StringBuffer> writer(sbuffer);
writer.StartObject();
writer.String("app_id"); writer.String(app_id.c_str());
if(data_type == 0) {
string encode_data = b64_encode(imageData);
writer.String("image"); writer.String(encode_data.c_str());
}else {
writer.String("url"); writer.String(imagePath.c_str());
}
if(!cookie.empty()) {
writer.String("cookie"); writer.String(cookie.c_str());
}
writer.EndObject();
req = sbuffer.GetString();
int ret = curl_method(addr, req, rsp);
if(ret == 0) {
result.Parse<rapidjson::kParseStopWhenDoneFlag>(rsp.c_str());
if(result.HasParseError()) {
std::cout << "RapidJson parse error " << result.GetParseError() << endl;
return -1;
}
}else {
return -1;
}
return 0;
}
示例10: readJson
bool ComRender::readJson(const std::string &fileName, rapidjson::Document &doc)
{
bool ret = false;
do {
std::string contentStr = FileUtils::getInstance()->getStringFromFile(fileName);
if (contentStr.empty()) {
log("%s error: get string from %s failed!", __FUNCTION__, fileName.c_str());
break;
}
doc.Parse<0>(contentStr.c_str());
CC_BREAK_IF(doc.HasParseError());
ret = true;
} while (0);
return ret;
}
示例11: readJson
bool CCComRender::readJson(const char *pszFileName, rapidjson::Document &doc)
{
bool bRet = false;
unsigned long size = 0;
unsigned char *pBytes = NULL;
do {
CC_BREAK_IF(pszFileName == NULL);
std::string jsonpath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFileName);
pBytes = cocos2d::CCFileUtils::sharedFileUtils()->getFileData(jsonpath.c_str(), "r", &size);
CC_BREAK_IF(pBytes == NULL || strcmp((char*)pBytes, "") == 0);
std::string load_str((const char*)pBytes, size);
CC_SAFE_DELETE_ARRAY(pBytes);
doc.Parse<0>(load_str.c_str());
CC_BREAK_IF(doc.HasParseError());
bRet = true;
} while (0);
return bRet;
}
示例12: loadJSON
int SettingRegistry::loadJSON(std::string filename, rapidjson::Document& json_document)
{
FILE* f = fopen(filename.c_str(), "rb");
if (!f)
{
cura::logError("Couldn't open JSON file.\n");
return 1;
}
char read_buffer[4096];
rapidjson::FileReadStream reader_stream(f, read_buffer, sizeof(read_buffer));
json_document.ParseStream(reader_stream);
fclose(f);
if (json_document.HasParseError())
{
cura::logError("Error parsing JSON(offset %u): %s\n", (unsigned)json_document.GetErrorOffset(), GetParseError_En(json_document.GetParseError()));
return 2;
}
return 0;
}
示例13: loadDocument
inline bool loadDocument(const std::string &path, rapidjson::Document &document)
{
// Load schema JSON from file
std::string file;
if (!loadFile(path, file)) {
std::cerr << "Failed to load json from file '" << path << "'." << std::endl;
return false;
}
// Parse schema
document.Parse<0>(file.c_str());
if (document.HasParseError()) {
std::cerr << "RapidJson failed to parse the document:" << std::endl;
std::cerr << "Parse error: " << document.GetParseError() << std::endl;
std::cerr << "Near: " << file.substr(std::max(size_t(0), document.GetErrorOffset() - 20), 40) << std::endl;
return false;
}
return true;
}
示例14: DelFace
int ytopen_sdk::DelFace(rapidjson::Document &result, const string& person_id, const std::vector<string>& face_ids)
{
std::stringstream ss;
ss<<host<<"/youtu/api/delface";
string addr;
addr.assign(ss.str());
string req;
string rsp;
StringBuffer sbuffer;
Writer<StringBuffer> writer(sbuffer);
writer.StartObject();
writer.String("app_id"); writer.String(app_id.c_str());
writer.String("person_id"); writer.String(person_id.c_str());
writer.String("face_ids");
writer.StartArray();
for(int i = 0; i < face_ids.size(); i++)
{
writer.String(face_ids[i].c_str());
}
writer.EndArray();
writer.EndObject();
req = sbuffer.GetString();
int ret = curl_method(addr, req, rsp);
if(ret == 0) {
result.Parse<rapidjson::kParseStopWhenDoneFlag>(rsp.c_str());
if(result.HasParseError()) {
std::cout << "RapidJson parse error " << result.GetParseError() << endl;
return -1;
}
}else {
return -1;
}
return 0;
}
示例15: _loadConfig
bool Utils::_loadConfig(const char *filename, rapidjson::Document &doc, KVMap &kvmap, bool &bLoaded)
{
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename);
std::string fileContent = FileUtils::getInstance()->getStringFromFile(fullPath);
doc.Parse<0>(fileContent.c_str());
if (doc.HasParseError()) {
CCLOG("GetParseError %s\n", doc.GetParseError());
return false;
}
for (rapidjson::Value::ConstMemberIterator it=doc.MemberonBegin(); it!=doc.MemberonEnd(); ++it)
{
const auto &member = *it;
const char *name = member.name.GetString();
const rapidjson::Value &val = member.value;
kvmap.insert(Utils::KVMapPair(name, val));
}
bLoaded = true;
return true;
}