I don't want JSON to escape apostrophes in C++. How to fix this? -


i've encountered bit of problem json (libjson 6). in chat messenger making, there conflict between server (which made other people) , desktop client. client's json strings have apostrophes escaped, though use quotes delimit strings. server, on other hand, doesn't expect apostrophes escaped, leads situations client sends \' creates problems server's parser.

the way me solve this, making program stop escaping apostrophes in json messages. however, after searching on google , in documentation, haven't found anything. can tell me how this?

you can remove escapes before apostrophes.

if never have escaped escapes before apostrophe (e.g. \\' meaning "escaped-escape , unescaped apostrophe") or library escapes them, replace \' '. there various string replace functions, simple case:

bool is_broken_escaped_apos(std::string const &data, std::string::size_type n) {   return n + 2 <= data.size()      , data[n] == '\\'      , data[n+1] == '\''; } void fix_broken_escaped_apos(std::string &data) {   (std::string::size_type n = 0; n != data.size(); ++n) {     if (is_broken_escaped_apos(data, n)) {       data.replace(n, 2, 1, '\'');     }   } } 

otherwise, you'll have parse subset of string escapes, more involved, not hard.


Comments

Popular posts from this blog

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -

jQuery clickable div with working mailto link inside -