简体   繁体   中英

C++: Consider the literal meaning of double quotes(") in a C++ std::string without using backslash (\)

I've a JSON data received in string format.

std::string jsonStr = GetJsonStringBuffer();

// It might get stored in jsonStr like this:

jsonStr = " {"Key1":"val1","key2" : "val2","key3" : "val3"} " ;

BUt JSON string itself has double quotes (") in it. So when GetJsonStringBuffer() returns a C++ std::string is stored in jsonStr . Will it not create an issue as the double quotes(") withn the json data might be considered as string separator of C++ std::string.

How to handle this situation. Do I programatically append a "\\" (backslash) for every double quote within the json string which i don't think is a great solution. Any better C++ solution for this ?

带有"的字符串没有问题。C++中双引号的唯一问题是在编译时双引号出现在源代码中的文字中。这就是反斜杠的用途。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM