How to Encode/Decode String?

Apr 26, 2014 at 7:11 PM
Is there a conversion utility to encode/decode a string? Or what is the best practice? I'm starting from a C string:

char *s = "hello\"world\n";


file << U("\"name\" : ") << U("\"") << s << U("\"");

to create the line:

"name" : "hello\"world\n"
Apr 26, 2014 at 7:52 PM
Hi BSalita,

Specifically what kind of encoding/decoding are you talking about? For the code you mention it looks like you are trying to do something escaping quotes producing some sort of pair, perhaps for a json object?

Apr 26, 2014 at 7:58 PM
Yes, a line of a JSON object in source code. My app creates JSON source code, sometimes with data originating from a C string.
Apr 26, 2014 at 8:18 PM
Hi BSalita,

No we currently do have any facility exposed for doing this. You could take you 'name' and 'hello world' string and construct a json object and then serialize to a string. Will this not give you the same thing?

If not you can open a feature request under issues, but even better you could add this functionality and contribute back.

Apr 26, 2014 at 8:29 PM
Thanks. That's what I needed to know. It would be helpful if there was a method for converting a string to JSON string literal encoding. I'll just write one myself. I hope to post some of the project's code. The project moves into beta next week. I'll ask the boss how much I can contribute.
Apr 27, 2014 at 6:40 PM
If you look in json_serialization.cpp you can find the code for that functionality in a method called append_escape_string. Let me know if you are interested in contributing back.