I'm trying to pass a JSON object containing a path
from my frontend (Node) to the backend (C++) using RapidJSON, like so:
#include <iostream>
#include "rapidjson/document.h"
int main() {
const char* json1 = "{\"path\":\"C:\\test.file\"}"; // works
const char* json2 = "{\"path\":\"C:\\fol der\\test.file\"}"; // works
const char* json3 = "{\"path\":\"C:\\fol der\\Test.file\"}"; // ERROR!
const char* json4 = "{\"path\":\"C:\\few dol\\test.file\"}"; // ERROR!
const char* json5 = "{\"path\":\"C:\\folder\\anotherOne\\test.file\"}"; // ERROR!
rapidjson::Document d;
d.Parse(json3); // works using json1 or json2
assert(d.HasMember("path"));
std::string pathString = d["path"].GetString();
return 0;
}
The first two strings work. However, I can't get any longer paths to work and even capitalization is giving me trouble (the only difference between json2
and json3
is the "T").
How do I properly pass and parse paths (Windows and maybe Linux)?
Thank you in advance!
Edit: I just tried nlohman's JSON library and have the same problem.
How do I pass paths in JSON???