RapidJSON c ++:MemoryPoolAllocator崩溃MAC

时间:2018-08-23 05:55:09

标签: c++ xcode macos-sierra rapidjson

当我尝试在C ++ XCode MAC应用程序中解析JSON字符串时,有时它在下面崩溃:

示例代码:

int ResponseHandler::HgetName(std::string strResponse, std::vector<std::string>& strName) {

LOG_CPS_BEGINTRACE(wxT("ResponseHandler::HgetName:ENTER"))
    try
{
    if (strResponse.empty())
    {
        LOG_CPS_ERROR(wxT("ResponseHandler::HgetName:Response Got Nothing..."))
            return -1;
    }
    int StringSize = strResponse.length() + 1;
    char* jsonStr = new char[StringSize];
    std::string name;
    SafeStrCopy(jsonStr, strResponse.c_str());

    rapidjson::Document doc;
    rapidjson::Value::MemberIterator iter;
    doc.Parse(jsonStr);

    int i = 0;

    for (rapidjson::Value::ConstValueIterator arrayIter = doc["data"]["items"].Begin(); arrayIter != doc["data"]["items"].End(); ++arrayIter)
    {
        bool skip = false;
        for (Value::ConstMemberIterator itr = arrayIter->MemberBegin();
            itr != arrayIter->MemberEnd(); ++itr)
        {
            const string& memberKey = itr->name.GetString();

            if (strcmp("name", memberKey.c_str()) == 0)
            {
                strName.push_back( itr->value.GetString());
            }
        }
        ++i;
    }
    delete[] jsonStr;
    LOG_CPS_ENDTRACE(wxT("ResponseHandler::HgetName:EXIT"))
        return 0;
}
catch (...)
{
    LOG_CPS_ERROR(wxT("ResponseHandler::HgetName :Exception"))
        return -1; //TODO:
}
}
Crash Report: rapidjson::internal::DisableIf<rapidjson::internal::RemoveSfinaeTag<rapidjson::internal::SfinaeTag&
 (*)(rapidjson::internal::NotExpr<rapidjson::internal::IsSame<rapidjson::internal::RemoveConst<char
 const>::Type, char> >)>::Type,
 rapidjson::GenericValue<rapidjson::UTF8<char>,
 rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >&>::Type
 rapidjson::GenericValue<rapidjson::UTF8<char>,
 rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>
::operator[]<char const>(char const*) + 331\

任何人都可以帮忙。

谢谢

0 个答案:

没有答案