0

I need to parse json in my C++ program. I decided to use RapidJson library for this purpose, but I got "abort() has been called" error. I truncated the code to this:

#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;
}

but I got the error again. Where is the mistake? Thanks in advance!

1 Answers1

1

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

there is a character before the left brace.

Daniel
  • 573
  • 4
  • 11
  • It's used to cast to 16 bits. Check [this answer](https://stackoverflow.com/a/23452555/6683995) – Raghav May 14 '18 at 13:31
  • Thank you very much! At first I though that you meant symbol 'L', but then I discovered an invisible symbol between ' " ' and '{'. I have no idea, how it got there, but the problem is solved! – Андрій Немченко May 14 '18 at 14:10