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 2021/05/07 02:10:40 UTC

[GitHub] [apisix] sniper-xx opened a new issue #4193: request help: how to resovle cjson decode empty array and emtpy object separately?

sniper-xx opened a new issue #4193:
URL: https://github.com/apache/apisix/issues/4193


   ### Issue description
   
   The json data from the backend server, both have empty array and empty object. when decode the json data, it's only to controll cjson decode either to array or to object. but that leads to troubles. Is there any resolution to resolve this proplem?
   


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] sniper-xx commented on issue #4193: request help: how to resovle cjson decode empty array and emtpy object separately?

Posted by GitBox <gi...@apache.org>.
sniper-xx commented on issue #4193:
URL: https://github.com/apache/apisix/issues/4193#issuecomment-834053430


   I try to replace the content string,but i don't known whether it affects performance?


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #4193: request help: how to resovle cjson decode empty array and emtpy object separately?

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #4193:
URL: https://github.com/apache/apisix/issues/4193#issuecomment-834113831


   > 
   > 
   > What about using `decode_array_with_array_mt`? [openresty/lua-cjson#decode_array_with_array_mt](https://github.com/openresty/lua-cjson#decode_array_with_array_mt)
   > Can it solve your problem?
   
   It may solve your problem


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] sniper-xx commented on issue #4193: request help: how to resovle cjson decode empty array and emtpy object separately?

Posted by GitBox <gi...@apache.org>.
sniper-xx commented on issue #4193:
URL: https://github.com/apache/apisix/issues/4193#issuecomment-834052749


   Is there any resolution to resovle this proplem?  I expected the empty array is decoded a array. the empty object is decoded a object.


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] sniper-xx commented on issue #4193: request help: how to resovle cjson decode empty array and emtpy object separately?

Posted by GitBox <gi...@apache.org>.
sniper-xx commented on issue #4193:
URL: https://github.com/apache/apisix/issues/4193#issuecomment-834145313


   It's solved using decode_array_with_array_mt. thanks!


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] sniper-xx commented on issue #4193: request help: how to resovle cjson decode empty array and emtpy object separately?

Posted by GitBox <gi...@apache.org>.
sniper-xx commented on issue #4193:
URL: https://github.com/apache/apisix/issues/4193#issuecomment-834050995


   ```lua
   local function wrap_result(conf, ctx)
       local result = {
           msg="ok",
           code= resp_code,
           elapsed = ngx.time()-elapsed,
           data = "__placeholder__",
           success=true
       }
   
       --如果完成后台数据读取,重新进行Json结果封装
       result['data'] = cjson_decode(data_buffer)
       ngx.arg[1] = cjson_encode(result)
       --local wrap_string = cjson_encode(result)
       --local ret_content = ngx.re.sub(wrap_string,'"__placeholder__"',data_buffer,'jo')
       --ngx.arg[1] = ret_content
       ngx.arg[2] = true
   end
   ```


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] sniper-xx commented on issue #4193: request help: how to resovle cjson decode empty array and emtpy object separately?

Posted by GitBox <gi...@apache.org>.
sniper-xx commented on issue #4193:
URL: https://github.com/apache/apisix/issues/4193#issuecomment-834052036


   The apisix use as a gateway. I want to wrap the result of backend service.  but the empty array and empty object both exists in the backend data. the problem is both empty object and empty array is encoded to either object or array.


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #4193: request help: how to resovle cjson decode empty array and emtpy object separately?

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #4193:
URL: https://github.com/apache/apisix/issues/4193#issuecomment-834046289


   What about using `decode_array_with_array_mt`? https://github.com/openresty/lua-cjson#decode_array_with_array_mt
   Can it solve your problem?


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #4193: request help: how to resovle cjson decode empty array and emtpy object separately?

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #4193:
URL: https://github.com/apache/apisix/issues/4193#issuecomment-834020283


   Could you provide an example?
   
   `[]` will be decoded as an empty array, `{}` will be an empty object. It is not a problem.


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander closed issue #4193: request help: how to resovle cjson decode empty array and emtpy object separately?

Posted by GitBox <gi...@apache.org>.
spacewander closed issue #4193:
URL: https://github.com/apache/apisix/issues/4193


   


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org