如何将嵌套字典转换为 json 对象 - Odoo12?
How to convert nested dictionary into json object - Odoo12?
我正在尝试 return 嵌套词典作为 json 对象,但我遇到了以下错误。
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 270, in run_wsgi
execute(self.server.app)
File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 258, in execute
application_iter = app(environ, start_response)
File "/home/user/Projects/odoo_12_EE/odoo/service/server.py", line 409, in app
return self.app(e, s)
File "/home/user/Projects/odoo_12_EE/odoo/service/wsgi_server.py", line 128, in application
return application_unproxied(environ, start_response)
File "/home/user/Projects/odoo_12_EE/odoo/service/wsgi_server.py", line 117, in application_unproxied
result = odoo.http.root(environ, start_response)
File "/home/user/Projects/odoo_12_EE/odoo/http.py", line 1318, in call
return self.dispatch(environ, start_response)
File "/home/user/Projects/odoo_12_EE/odoo/http.py", line 1291, in call
return self.app(environ, start_wrapped)
File "/usr/local/lib/python3.6/dist-packages/werkzeug/wsgi.py", line 766, in call
return self.app(environ, start_response)
File "/home/user/Projects/odoo_12_EE/odoo/http.py", line 1491, in dispatch
return response(environ, start_response)
TypeError: 'dict' object is not callable - - -
这是我的代码。
controller.py
class GetOrderStatus(http.Controller):
@http.route('/getOrderStatus/<string:order_num>',type="http",method=['POST','GET'],website=False,auth="public")
def _get_order_status(self,**kw):
print('kwww',kw)
order_id = request.env['helpdesk.ticket'].sudo().search([('name','=',kw.get('order_num'))])
order_id.ensure_one()
vals = {
"statusCode":200,
"statuDescription":"success",
"data":{"order_status":order_id.stage_id.name}
}
print('vals',vals)
n = json.dumps(vals)
return json.loads(n)
我该如何解决这个问题?
如果您想连同您的回复一起发送 json 数据,请将其设为 json 类型请求。
from odoo.http import Response
import json
class GetOrderStatus(http.Controller):
@http.route('/getOrderStatus/<string:order_num>', type="json", method=['POST','GET'], website=False, auth="public", csrf=False)
def _get_order_status(self,**kw):
order_id = request.env['helpdesk.ticket'].sudo().search([('name','=',kw.get('order_num'))])
order_id.ensure_one()
return Response(json.dumps({"order_status":order_id.stage_id.name}),content_type='application/json;charset=utf-8',status=200)
我正在尝试 return 嵌套词典作为 json 对象,但我遇到了以下错误。
Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 270, in run_wsgi execute(self.server.app) File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 258, in execute application_iter = app(environ, start_response) File "/home/user/Projects/odoo_12_EE/odoo/service/server.py", line 409, in app return self.app(e, s) File "/home/user/Projects/odoo_12_EE/odoo/service/wsgi_server.py", line 128, in application return application_unproxied(environ, start_response) File "/home/user/Projects/odoo_12_EE/odoo/service/wsgi_server.py", line 117, in application_unproxied result = odoo.http.root(environ, start_response) File "/home/user/Projects/odoo_12_EE/odoo/http.py", line 1318, in call return self.dispatch(environ, start_response) File "/home/user/Projects/odoo_12_EE/odoo/http.py", line 1291, in call return self.app(environ, start_wrapped) File "/usr/local/lib/python3.6/dist-packages/werkzeug/wsgi.py", line 766, in call return self.app(environ, start_response) File "/home/user/Projects/odoo_12_EE/odoo/http.py", line 1491, in dispatch return response(environ, start_response) TypeError: 'dict' object is not callable - - -
这是我的代码。 controller.py
class GetOrderStatus(http.Controller):
@http.route('/getOrderStatus/<string:order_num>',type="http",method=['POST','GET'],website=False,auth="public")
def _get_order_status(self,**kw):
print('kwww',kw)
order_id = request.env['helpdesk.ticket'].sudo().search([('name','=',kw.get('order_num'))])
order_id.ensure_one()
vals = {
"statusCode":200,
"statuDescription":"success",
"data":{"order_status":order_id.stage_id.name}
}
print('vals',vals)
n = json.dumps(vals)
return json.loads(n)
我该如何解决这个问题?
如果您想连同您的回复一起发送 json 数据,请将其设为 json 类型请求。
from odoo.http import Response
import json
class GetOrderStatus(http.Controller):
@http.route('/getOrderStatus/<string:order_num>', type="json", method=['POST','GET'], website=False, auth="public", csrf=False)
def _get_order_status(self,**kw):
order_id = request.env['helpdesk.ticket'].sudo().search([('name','=',kw.get('order_num'))])
order_id.ensure_one()
return Response(json.dumps({"order_status":order_id.stage_id.name}),content_type='application/json;charset=utf-8',status=200)