You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/12/10 11:06:09 UTC
[GitHub] [apisix] dickens7 opened a new issue, #8498: help request: How to implement `apisix.core.json` encode output Unicode characters
dickens7 opened a new issue, #8498:
URL: https://github.com/apache/apisix/issues/8498
### Description
How do I output Unicode characters in Apisix using the encode function of `apisix.core.json`?
```lua
local json = require "apisix.core.json"
local t = {aaa = "aaaa", bbb = "你好,世界"}
local json_str = cjson.encode(t)
print(json_str)
```
Expected output
```json
{"aaa":"aaaa","message":"\u4f60\u597d,\u4e16\u754c"}
```
### Environment
- APISIX version (run `apisix version`):
- Operating system (run `uname -a`):
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
- etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):
- APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run `luarocks --version`):
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] dickens7 commented on issue #8498: help request: How to implement `apisix.core.json` encode output Unicode characters
Posted by GitBox <gi...@apache.org>.
dickens7 commented on issue #8498:
URL: https://github.com/apache/apisix/issues/8498#issuecomment-1347631654
@pixeldin Thanks, the `cjson` here is wrong when pasting the code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] dickens7 closed issue #8498: help request: How to implement `apisix.core.json` encode output Unicode characters
Posted by "dickens7 (via GitHub)" <gi...@apache.org>.
dickens7 closed issue #8498: help request: How to implement `apisix.core.json` encode output Unicode characters
URL: https://github.com/apache/apisix/issues/8498
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on issue #8498: help request: How to implement `apisix.core.json` encode output Unicode characters
Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #8498:
URL: https://github.com/apache/apisix/issues/8498#issuecomment-1347809321
I tried:
```
=== TEST 18: hit
--- ONLY
--- config
location /t {
content_by_lua_block {
local json = require "apisix.core.json"
local t = {aaa = "aaaa", bbb = "你好,世界"}
local json_str = json.encode(t)
ngx.print(json_str)
}
}
--- response_body
```
Got: `{"bbb":"你好,世界","aaa":"aaaa"}`.
It works fine for me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #8498: help request: How to implement `apisix.core.json` encode output Unicode characters
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8498:
URL: https://github.com/apache/apisix/issues/8498#issuecomment-1347825805
accord to: http://lua-users.org/wiki/LuaUnicode
It seems that the "convert a character to a string in unicode" you want is not possible.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #8498: help request: How to implement `apisix.core.json` encode output Unicode characters
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #8498:
URL: https://github.com/apache/apisix/issues/8498#issuecomment-1347810064
what his' expected output is
```json
{"aaa":"aaaa","message":"\u4f60\u597d,\u4e16\u754c"}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] pixeldin commented on issue #8498: help request: How to implement `apisix.core.json` encode output Unicode characters
Posted by GitBox <gi...@apache.org>.
pixeldin commented on issue #8498:
URL: https://github.com/apache/apisix/issues/8498#issuecomment-1345482724
This looks like an encoding issue you are occured. And from your example, you import with the ```local json = require "apisix.core.json"``` but using the ```cjson.encode(t)```.
You may try this?
```
local json = require "apisix.core.json"
local t = {aaa = "aaaa", bbb = "你好,世界"}
local json_str = json.encode(t)
print(json_str)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] dickens7 commented on issue #8498: help request: How to implement `apisix.core.json` encode output Unicode characters
Posted by GitBox <gi...@apache.org>.
dickens7 commented on issue #8498:
URL: https://github.com/apache/apisix/issues/8498#issuecomment-1347821500
> what his' expected output is
>
> ```json
> {"aaa":"aaaa","message":"\u4f60\u597d,\u4e16\u754c"}
> ```
Yes, that's what I expect.
I looked into it and it seems like I can only implement a `utf8_to_unicode` on my own
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org