1. If there are attributes in the JSON object that contain double quotes, such as
Copy Code code as follows:
{
"description": "25" "
}
If converted to a string form, the backslash is automatically added to "25\" and then passed to the rest API and saved to the MongoDB.
At this point, if you use the MongoDB shell to display the data, "25\", correct.
2. However, if you read this value in C + + driver, you get "25", so if you return it directly to the browser end, you can use Jquery.parsejson () to parse the error.
The C + + segment is serialized into a string that needs to be judged by "Replace with \".
Copy Code code as follows:
void string_to_json_string (std::string const& str, std::string & json_str) {
Std::stringstream SS;
for (size_t i = 0; i < str.length (); ++i) {
if (str[i] = = ' "') {
SS << ' \ \ ' << ' ';
} else {
SS << Str[i];
}
}
Json_str = Ss.str ();
}
3. If JavaScript calls Jquery.parsejson () on "25\", the backslash disappears and becomes "25". If you call Jquery.paresejson on the property value again, you will get an error.
JavaScript must write code to prevent errors:
Copy Code code as follows:
Removedoublequotes:function (str) {
return str.replace ("\" "," \\\ ");
},
This is the reincarnation of double quotes in JSON. Enough trouble, be careful.