profile
viewpoint

Ask questionsJSON document comparison always returns true if it contains only a string value

If I have two JSON documents that only contain string values then RapidJSON parses them and considers their type to be kNullType... which then results in any two string-only JSON documents to be reported as being equal even when they are not.

The following code demonstrates this issue:

#include <iostream>
#include <rapidjson/document.h>

int main() {
    rapidjson::Document d1;
    d1.Parse("hello");

    rapidjson::Document d2;
    d2.Parse("world");

    std::cout << "JSON documents are equal: " << (d1 == d2 ? "Yes" : "No");

    std::cout << "JSON type: " << d1.GetType() << std::endl;

    return 0;
}

This gives the output:

JSON are equal: Yes
JSON type: 0
Tencent/rapidjson

Answer questions miloyip

These are not a valid JSON and parse() returns error. A valid JSON of a single string is, e.g., d1.Parse("\"hello\"");

useful!

Related questions

是否支持流式解析以及多个json分离解析 hot 1
是否支持流式解析以及多个json分离解析 hot 1
RapidJSON causes cc1plus: internal compiler error: Segmentation fault - rapidjson hot 1
GenericMemberIterator::Iterator implicitly declared private when RAPIDJSON_NOMEMBERITERATORCLASS is defined hot 1
Always gets a core dump while creating json string (rapidjson) hot 1
Bazel Support hot 1
Syntax typo in tutorial hot 1
是否支持流式解析以及多个json分离解析 hot 1
作者你好,我 想请教一下,这个框架是否能够将变量中文stirng 转成wchar_t? 在文档只看到定量 hot 1
travis on windows hot 1
Added headers to my project and got thousands of errors hot 1
Added headers to my project and got thousands of errors hot 1
想要的反斜杠 \. 无法表示,否则JSON解析出错 hot 1
Assertion `stack_.GetSize() == sizeof(ValueType)' failed hot 1
source:https://uonfu.com/
Github User Rank List