【问题标题】:rapidjson + c++: "abort() has been called" errorrapidjson + c++:“abort() 已被调用”错误
【发布时间】:2018-05-14 11:16:44
【问题描述】:

我需要在我的 C++ 程序中解析 json。我决定为此目的使用 RapidJson 库,但出现“abort() 已被调用”错误。我将代码截断为:

#include <iostream>
#include <cstdlib>
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/encodings.h"
#include "rapidjson/stringbuffer.h"

using namespace std;
using namespace rapidjson;

typedef GenericDocument<UTF16<> > WDocument;
typedef GenericValue<UTF16<> > WValue;

wchar_t request[] = L"{\"result\":\"OK\"}";

int main()
{
    WDocument d;
    d.Parse(request);
    WValue& v = d[L"result"]; // The exception throws here
    if (wcscmp(v.GetString(), L"OK"))
    {
        cout << "Success!" << endl;
    }
    else
        cout << "Fail!" << endl;
    system("pause");
    return 0;
}

但我又得到了错误。错误在哪里?提前致谢!

【问题讨论】:

    标签: c++ rapidjson


    【解决方案1】:

    检查这一行:
    wchar_t request[] = L"{\"result\":\"OK\"}";

    左大括号前有一个字符。

    【讨论】:

    • 用于转换为 16 位。检查this answer
    • 非常感谢!一开始我以为你的意思是符号'L',但后来我发现'"'和'{'之间有一个看不见的符号。我不知道它是怎么到那里的,但问题已经解决了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多