我想在浏览器窗口中回显服务器响应,这一切都非常漂亮。它是一个换行符分隔的字符串。
在浏览器窗口中回显,现在它看起来像这样:
pg_response_type=A pg_response_code=A01 pg_response_description=TEST APPROVAL pg_authorization_code=123456 pg_trace_number=81CE43B2-3740-404D-89CD-0C5F4EB26D05 pg_avs_code=Y pg_cvv_code=M pg_merchant_id=191620 pg_transaction_type=10 pg_total_amount=11.11 ecom_billto_postal_name_first=Forte ecom_billto_postal_name_last=Test ecom_billto_online_email=integration@forte.net pg_billto_postal_name_company=The Widget Company pg_merchant_data_3=custom data 3 pg_merchant_data_4=custom data 4 pg_customer_token=LghWTQzXQimxBLIcbnDHpQ pg_payment_token=YiQ24I5TTmWrFpJnJzcVYw endofdata
原始回复:
"pg_response_code=A01[\n]"
"pg_response_description=TEST APPROVAL[\n]"
"pg_authorization_code=123456[\n]"
"pg_trace_number=55A9A5D2-6174-4C40-88BA-98AFCE85D9F2[\n]"
"pg_avs_code=Y[\n]"
"pg_cvv_code=M[\n]"
"pg_merchant_id=191620[\n]"
"pg_transaction_type=10[\n]"
"pg_total_amount=19.99[\n]"
"pg_billto_postal_name_company=James Inc.[\n]"
"ecom_billto_postal_name_first=Bill[\n]"
"ecom_billto_postal_name_last=Customer[\n]"
"ecom_billto_online_email=james.ivey@forte.net[\n]"
endofdata
如何让它在浏览器窗口中显示出来并且非常漂亮?
pg_response_type=A
pg_response_code=A01
pg_response_description=TEST APPROVAL
pg_authorization_code=123456
pg_trace_number=81CE43B2-3740-404D-89CD-0C5F4EB26D05
pg_avs_code=Y
pg_cvv_code=M
pg_merchant_id=191620
pg_transaction_type=10
pg_total_amount=11.11
ecom_billto_postal_name_first=Forte
ecom_billto_postal_name_last=Test
ecom_billto_online_email=integration@forte.net
endofdata
PHP会很好,但欢迎任何解决方案或建议。谢谢!
答案 0 :(得分:0)
几个选项:
import itertools
from collections import ChainMap
sum_of_qty = [
list(b) for _, b in itertools.groupby(d, key=lambda x: [x[k] for k in x if k != 'qty'])
]
for i, item in enumerate(sum_of_qty):
sum_of_qty[i] = dict(ChainMap(*item))
sum_of_qty[i]['qty'] = sum(map(lambda x: x['qty'], item))
或white-space: pre;
代码。<pre>
的空格并用parse_str()解析,循环并构建漂亮的输出。