本文整理汇总了C++中Document::HasParseError方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::HasParseError方法的具体用法?C++ Document::HasParseError怎么用?C++ Document::HasParseError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document::HasParseError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: error
TYPED_TEST(DocumentMove, MoveAssignmentParseError) {
typedef TypeParam Allocator;
typedef GenericDocument<UTF8<>, Allocator> Document;
ParseResult noError;
Document a;
a.Parse("{ 4 = 4]");
ParseResult error(a.GetParseError(), a.GetErrorOffset());
EXPECT_TRUE(a.HasParseError());
EXPECT_NE(error.Code(), noError.Code());
EXPECT_NE(error.Offset(), noError.Offset());
Document b;
b = std::move(a);
EXPECT_FALSE(a.HasParseError());
EXPECT_TRUE(b.HasParseError());
EXPECT_EQ(a.GetParseError(), noError.Code());
EXPECT_EQ(b.GetParseError(), error.Code());
EXPECT_EQ(a.GetErrorOffset(), noError.Offset());
EXPECT_EQ(b.GetErrorOffset(), error.Offset());
Document c;
c = std::move(b);
EXPECT_FALSE(b.HasParseError());
EXPECT_TRUE(c.HasParseError());
EXPECT_EQ(b.GetParseError(), noError.Code());
EXPECT_EQ(c.GetParseError(), error.Code());
EXPECT_EQ(b.GetErrorOffset(), noError.Offset());
EXPECT_EQ(c.GetErrorOffset(), error.Offset());
}
示例2: tryDecode
/**
Attempts to decode JSON from the given data./
(Try cut end of given json)
\param [in] json The JSON.
\param [out] outJson The out JSON.
\param [out] outRest The out rest.
\return true if it succeeds, false if it fails.
*/
bool XJson::tryDecode(const std::string &json) {
// init output value
outRest = "";
string jsonText = json;
vector<string> rests;
Document doc;
string text, rest;
size_t foundPosition;
// try find valid part of json
do {
foundPosition = jsonText.rfind('}');
if (foundPosition == string::npos) {
text = jsonText;
jsonText = "";
}
else {
text = jsonText.substr(0, foundPosition + 1);
rest = jsonText.substr(foundPosition + 1, jsonText.length());
trimRestJson(rest);
if (rest != "") {
rests.push_back(rest);
jsonText = text;
}
else {
jsonText = "";
}
}
text = "[" + text + "]";
doc.Parse<0>(text.c_str());
} while (doc.HasParseError() && jsonText != ""); // try it while not succeed
// validate result
if (doc.HasParseError()) {
return false;
}
// create out rest
stringstream ssRest;
for (vector<string>::const_iterator it = rests.cend(); it != rests.cbegin(); --it) {
ssRest << *it;
}
outRest = ssRest.str();
// create out json
UrbiHandler handler;
doc.Accept(handler);
outJson = handler.getResult();
return true;
}
示例3: ifs
static void* pfwl_field_tags_load_L7(pfwl_field_id_t field, const char* fileName){
void* db = NULL;
if(pfwl_get_L7_field_type(field) == PFWL_FIELD_TYPE_STRING){
db = new pfwl_field_matching_db_t;
}else if(pfwl_get_L7_field_type(field) == PFWL_FIELD_TYPE_MMAP){
db = new std::map<std::string, pfwl_field_matching_db_t>;
}
if(fileName){
std::ifstream ifs(fileName);
IStreamWrapper isw(ifs);
Document d;
d.ParseStream(isw);
if (d.HasParseError()){
return NULL;
}
const Value& rules = d["rules"];
assert(rules.IsArray());
for (Value::ConstValueIterator itr = rules.Begin(); itr != rules.End(); ++itr) {
const Value& stringToMatch = (*itr)["value"];
const Value& matchingType = (*itr)["matchingType"];
const Value& tag = (*itr)["tag"];
if(pfwl_get_L7_field_type(field) == PFWL_FIELD_TYPE_STRING){
pfwl_field_string_tags_add_internal(static_cast<pfwl_field_matching_db_t*>(db), stringToMatch.GetString(), getFieldMatchingType(matchingType.GetString()), tag.GetString());
}else if(pfwl_get_L7_field_type(field) == PFWL_FIELD_TYPE_MMAP){
const Value& key = (*itr)["key"];
pfwl_field_mmap_tags_add_internal(static_cast<std::map<std::string, pfwl_field_matching_db_t>*>(db), key.GetString(), stringToMatch.GetString(), getFieldMatchingType(matchingType.GetString()), tag.GetString());
}
}
}
return db;
}
示例4: ParseGameTitlesFromFile
void ParseGameTitlesFromFile(std::map<GameID, std::string>& GameTitlesListOut)
{
SetCurrentDirectory(NativeStr(g_sHomeDir).c_str());
FILE* pf = nullptr;
fopen_s(&pf, RA_TITLES_FILENAME, "rb");
if (pf != nullptr)
{
Document doc;
doc.ParseStream(FileStream(pf));
if (!doc.HasParseError() && doc.HasMember("Success") && doc["Success"].GetBool() && doc.HasMember("Response"))
{
const Value& List = doc["Response"];
for (Value::ConstMemberIterator iter = List.MemberBegin(); iter != List.MemberEnd(); ++iter)
{
if (iter->name.IsNull() || iter->value.IsNull())
continue;
GameID nID = static_cast<GameID>(std::strtoul(iter->name.GetString(), nullptr, 10)); // KEYS ARE STRINGS, must convert afterwards!
const std::string sTitle = iter->value.GetString();
GameTitlesListOut[nID] = sTitle;
}
}
fclose(pf);
}
}
示例5: onLoginResponse
void LoginScene::onLoginResponse(HttpClient * sender, HttpResponse *response)
{
if (!response) return;
if (!response->isSucceed()) {
log("response failed");
log("error buffer: %s", response->getErrorBuffer());
return;
}
string res = Global::toString(response->getResponseData());
Document d;
d.Parse<0>(res.c_str());
if (d.HasParseError()) {
CCLOG("GetParseError %s\n", d.GetParseError());
}
if (d.IsObject() && d.HasMember("result") && d.HasMember("info")) {
bool result = d["result"].GetBool();
if (result) {
Global::saveStatus(response->getResponseHeader(), textField->getString());
Director::getInstance()->replaceScene(TransitionFade::create(1, GameScene::createScene()));
}
else {
CCLOG("Failed to login: %s\n", d["info"].GetString());
}
}
}
示例6: a
TYPED_TEST(DocumentMove, MoveAssignment) {
typedef TypeParam Allocator;
typedef GenericDocument<UTF8<>, Allocator> Document;
Allocator allocator;
Document a(&allocator);
a.Parse("[\"one\", \"two\", \"three\"]");
EXPECT_FALSE(a.HasParseError());
EXPECT_TRUE(a.IsArray());
EXPECT_EQ(3u, a.Size());
EXPECT_EQ(&a.GetAllocator(), &allocator);
// Document b; b = a; // does not compile (!is_copy_assignable)
Document b;
b = std::move(a);
EXPECT_TRUE(a.IsNull());
EXPECT_TRUE(b.IsArray());
EXPECT_EQ(3u, b.Size());
EXPECT_EQ(&a.GetAllocator(), (void*)0);
EXPECT_EQ(&b.GetAllocator(), &allocator);
b.Parse("{\"Foo\": \"Bar\", \"Baz\": 42}");
EXPECT_FALSE(b.HasParseError());
EXPECT_TRUE(b.IsObject());
EXPECT_EQ(2u, b.MemberCount());
// Document c; c = a; // does not compile (see static_assert)
Document c;
c = std::move(b);
EXPECT_TRUE(b.IsNull());
EXPECT_TRUE(c.IsObject());
EXPECT_EQ(2u, c.MemberCount());
EXPECT_EQ(&b.GetAllocator(), (void*)0);
EXPECT_EQ(&c.GetAllocator(), &allocator);
}
示例7: main
int main() {
Document d;
{
AsyncDocumentParser<> parser(d);
const char json1[] = " { \"hello\" : \"world\", \"t\" : tr";
//const char json1[] = " { \"hello\" : \"world\", \"t\" : trX"; // For test parsing error
const char json2[] = "ue, \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.14";
const char json3[] = "16, \"a\":[1, 2, 3, 4] } ";
parser.ParsePart(json1, sizeof(json1) - 1);
parser.ParsePart(json2, sizeof(json2) - 1);
parser.ParsePart(json3, sizeof(json3) - 1);
}
if (d.HasParseError()) {
std::cout << "Error at offset " << d.GetErrorOffset() << ": " << GetParseError_En(d.GetParseError()) << std::endl;
return EXIT_FAILURE;
}
// Stringify the JSON to cout
OStreamWrapper os(std::cout);
Writer<OStreamWrapper> writer(os);
d.Accept(writer);
std::cout << std::endl;
return EXIT_SUCCESS;
}
示例8: onGetRankResponse
void RankScene::onGetRankResponse(HttpClient * sender, HttpResponse *response) {
if (!response) return;
if (!response->isSucceed()) {
log("response failed");
log("error buffer: %s", response->getErrorBuffer());
return;
}
string res = Global::toString(response->getResponseData());
Document d;
d.Parse<0>(res.c_str());
if (d.HasParseError()) {
CCLOG("GetParseError %s\n", d.GetParseError());
}
if (d.IsObject() && d.HasMember("result") && d.HasMember("info")) {
bool result = d["result"].GetBool();
if (!result) {
CCLOG("Failed to login: %s\n", d["info"].GetString());
}
else {
setRankBoard(d["info"].GetString());
}
}
}
示例9: LoadFromFile
bool FileUtil::LoadFromFile(const Serializable::Ptr &source, const std::string &filePath)
{
using namespace rapidjson;
std::ifstream stream(filePath);
if (stream)
{
std::stringstream buffer;
buffer << stream.rdbuf();
Document dom;
dom.Parse(buffer.str().c_str());
if (dom.HasParseError())
{
LOGE << "Error parsing json file " << filePath << ": " << dom.GetParseError();
return false;
}
if (!source->Load(&dom))
{
LOGE << "Serialization failed!";
return false;
}
LOGD << filePath << " successfully deserialized!";
return true;
}
return false;
}
示例10: ParseGameHashLibraryFromFile
void ParseGameHashLibraryFromFile(std::map<std::string, GameID>& GameHashLibraryOut)
{
SetCurrentDirectory(NativeStr(g_sHomeDir).c_str());
FILE* pf = NULL;
fopen_s(&pf, RA_GAME_HASH_FILENAME, "rb");
if (pf != NULL)
{
Document doc;
doc.ParseStream(FileStream(pf));
if (!doc.HasParseError() && doc.HasMember("Success") && doc["Success"].GetBool() && doc.HasMember("MD5List"))
{
const Value& List = doc["MD5List"];
for (Value::ConstMemberIterator iter = List.MemberBegin(); iter != List.MemberEnd(); ++iter)
{
if (iter->name.IsNull() || iter->value.IsNull())
continue;
const std::string sMD5 = iter->name.GetString();
//GameID nID = static_cast<GameID>( std::strtoul( iter->value.GetString(), NULL, 10 ) ); // MUST BE STRING, then converted to uint. Keys are strings ONLY
GameID nID = static_cast<GameID>(iter->value.GetUint());
GameHashLibraryOut[sMD5] = nID;
}
}
fclose(pf);
}
}
示例11: parseAttributeValue
/* ****************************************************************************
*
* parseAttributeValue -
*/
std::string parseAttributeValue(ConnectionInfo* ciP, ContextAttribute* caP)
{
Document document;
OrionError oe;
document.Parse(ciP->payload);
if (document.HasParseError())
{
alarmMgr.badInput(clientIp, "JSON parse error");
oe.reasonPhrase = ERROR_STRING_PARSERROR;
oe.details = "Errors found in incoming JSON buffer";
ciP->httpStatusCode = SccBadRequest;;
return oe.render(ciP, "");
}
if (!document.IsObject() && !document.IsArray())
{
alarmMgr.badInput(clientIp, "JSON parse error");
oe.fill(SccBadRequest, "Neither JSON Object nor JSON Array for attribute::value");
ciP->httpStatusCode = SccBadRequest;;
return oe.render(ciP, "");
}
caP->valueType = (document.IsObject())? orion::ValueTypeObject : orion::ValueTypeVector;
parseContextAttributeCompoundValueStandAlone(document, caP, caP->valueType);
return "OK";
}
示例12:
TEST(Document, UnchangedOnParseError) {
Document doc;
doc.SetArray().PushBack(0, doc.GetAllocator());
ParseResult err = doc.Parse("{]");
EXPECT_TRUE(doc.HasParseError());
EXPECT_EQ(err.Code(), doc.GetParseError());
EXPECT_EQ(err.Offset(), doc.GetErrorOffset());
EXPECT_TRUE(doc.IsArray());
EXPECT_EQ(doc.Size(), 1u);
err = doc.Parse("{}");
EXPECT_FALSE(doc.HasParseError());
EXPECT_FALSE(err.IsError());
EXPECT_EQ(err.Code(), doc.GetParseError());
EXPECT_EQ(err.Offset(), doc.GetErrorOffset());
EXPECT_TRUE(doc.IsObject());
EXPECT_EQ(doc.MemberCount(), 0u);
}
示例13: testJson
bool testJson(const char *json, size_t &line, size_t &col) {
StringStream ss(json);
CursorStreamWrapper<StringStream> csw(ss);
Document document;
document.ParseStream(csw);
bool ret = document.HasParseError();
if (ret) {
col = csw.GetColumn();
line = csw.GetLine();
}
return ret;
}
示例14: send
::urbi::UValue XJson::decode(const std::string &json) {
Document doc;
doc.Parse<0>(json.c_str());
if (doc.HasParseError()) {
send("throw \"Cannot parse JSON.\";");
// would return nil UValue
}
UrbiHandler handler;
doc.Accept(handler);
return handler.getResult();
}
示例15: ParseDouble
virtual bool ParseDouble(const char* json, double* d) const {
Document doc;
#ifdef TEST_INSITU
RapidjsonParseResult pr(json, strlen(json));
doc.ParseInsitu<TEST_PARSE_FLAG>(pr.buffer);
#else
doc.Parse<TEST_PARSE_FLAG>(json);
#endif
if (!doc.HasParseError() && doc.IsArray() && doc.Size() == 1 && doc[0].IsNumber()) {
*d = doc[0].GetDouble();
return true;
}
return false;
}