思路就是:字符串是个json格式(或转为json格式),然后str转为字典dict,然后循环遍历按照key来取值。
你的data是个字典 然后item_list是data的Key ,item_list是个数组,这个里面的数组中的每个元素都是一个字典。
因此就是dict多级路径按key取值。
import json data1 = '{"data":{"itemList":[{"createTime":1647412030000,"createUserName":"\u9999\u683C\u91CC\u62C9\u5927\u9B54\u738B","discountAmount":0.0000,"id":1204,"orderNo":"291940461143523328","orderPrice":0.1000,"orderStatus":1,"payPrice":0.1000,"payTime":1647412038000,"payType":"weixin","qualifiedCity":"\u5168\u56FD","quantity":1,"refundAccount":null,"refundAmount":null,"refundNotifyTime":null,"refundTime":null,"rightsEndTime":1649952000000,"rightsStartTime":1647446400000,"salePrice":0.10,"skuCode":"202201171927","skuName":"\u3010HTML\u6D4B\u8BD5\u3011\u6559\u7EC3\u89C6\u9891\u6743\u76CA\u5361","skuPrivilegeType":"buick_privilege_type_video","skuPropertyValue":"\u6708\u5361","targetId":64264,"transOrderStatus":5},,{"createTime":1641782671000,"createUserName":"\u6559\u7EC3\u4E8C","discountAmount":0.0000,"id":572,"orderNo":"268329217627127808","orderPrice":0.0100,"orderStatus":2,"payPrice":0.0100,"payTime":1641782681000,"payType":"weixin","qualifiedCity":"\u5168\u56FD","quantity":1,"refundAccount":null,"refundAmount":null,"refundNotifyTime":null,"refundTime":null,"rightsEndTime":1657296000000,"rightsStartTime":1641744000000,"salePrice":0.01,"skuCode":"202201061843","skuName":"\u6559\u7EC3\u89C6\u9891\u6743\u76CA\u5361","skuPrivilegeType":"buick_privilege_type_video","skuPropertyValue":"\u534A\u5E74\u5361","targetId":64841,"transOrderStatus":2}]},"errorCode":0,"message":null,"paging":{"page":1,"total":40},"reqId":"1FU8ODQCR1CU","success":true,"traceId":""}' payPrice_list = json.loads(data1) # print(type(payPrice_list)) # print(payPrice_list) cou = 0 for i in payPrice_list['data']['itemList']: nub = float(i['payPrice']) cou = nub+cou print(i['payPrice']) print(cou)