我必须将数组返回给json请求,但是我遇到了问题
API需要这样做:
[{"pagado":false,"forma_pago":"Procard - Tarjetas de crédito","fecha_pago":null,"monto":"762542.75","fecha_maxima_pago":"2019-02-15 19:30:00","hash_pedido":"247a29c410c278cf1f8ed24db46bf17c3461b96df7cbb5036cbce4fbf20c8e0a","numero_pedido":"194188","cancelado":false,"forma_pago_identificador":"1","token":"f48d99ae8d313142e9fb68260e01dc1c65540544"}]
并且API接收到此
{"jsonrpc":"2.0","id":null,"result":"[{'pagado': False, 'forma_pago': 'Procard - Tarjetas de cr\u00e9dito', 'fecha_pago': None, 'monto': '762542.75', 'fecha_maxima_pago': '2019-02-15 19:30:00', 'hash_pedido': '247a29c410c278cf1f8ed24db46bf17c3461b96df7cbb5036cbce4fbf20c8e0a', 'numero_pedido': '194188', 'cancelado': False, 'forma_pago_identificador': '1', 'token': 'f48d99ae8d313142e9fb68260e01dc1c65540544'}]"}
我只需要返回数组,我不知道我的问题,这是我的控制器的代码
@http.route('/pagopar/confirmacion_pago/', auth='public', methods=['POST'], type='json', csrf=False)
def index(self, **post):
data1 = request.httprequest.data
my_json = data1.decode('utf8').replace("'", '"')
data_dict = json.loads(my_json)
a = 0
if data_dict['respuesta']:
if True:
arr_return = []
arr_return.append(data_dict['resultado'][0])
return {'response': arr_return[0]}
在返回之前,我将arr_return [0]打印到我的日志中,并且得到了很好的结果,但是API没有
谢谢! 对不起,我的英语不好