Hi, i'm using Nim a week and stil cannot find the way to work with json in utf8. I have this:
let json_resp = query.getContent()
echo json_resp
let parsed = parseJson(json_resp)
echo parsed
I have also imported unicode, strutils and json modules. And this is output:
{"status":1,"status_message":"Не указан уникальный идентификатор мероприятия"}
{"status":1,"status_message":"\u041D\u0435 \u0443\u043A\u0430\u0437\u0430\u043D \u0443\u043D\u0438\u043A\u0430\u043B\u044C\u043D\u044B\u0439 \u0438\u0434\u0435\u043D\u0442\u0438\u0444\u0438\u043A\u0430\u0442\u043E\u0440 \u043C\u0435\u0440\u043E\u043F\u0440\u0438\u044F\u0442\u0438\u044F"}
As you can see without using "parseJson" everything is ok with encoding. Also, the same trouble with using % operator(the same modules was imported):
var s = "блаблабла"
echo s
echo (%s)
And I get:
блаблабла
"\u0431\u043B\u0430\u0431\u043B\u0430\u0431\u043B\u0430"
It seems I'm doing something wrong, but it's really unusual behaviour for me. I cann't find anything in modules description.
Thank you
This is quite normal. You are first printing a string, then a json node. When Nim prints a json node, it escapes characters outside the range \u0020 to \u007f. When printing a string, it just prints the raw characters and doesn't escape them.
To get at the underlying representation of a string, use getStr on the json node. E.g.:
echo getStr(%s)