如何从 JSON 响应中获取特定值 - Python
How to get a specific value from a JSON response - Python
我开始使用 python,现在我正尝试从 REST 中检索一些值,但是我收到一个错误
Traceback (most recent call last):
File "h:\DESKTOP\test_check\check_securityPrices.py", line 69, in <module>
jsonPath = r["assetPricing"]["instrumentId"]
TypeError: list indices must be integers or slices, not str
这是我得到的 JSON 响应:
[{
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380992',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380992',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 141.96875,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 142.054687,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 142.140625,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 141.984375,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 141.984375,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 143.569973,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 143.65591,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 143.741848,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 141.953125,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 142.039063,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 142.125,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380993',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380993',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 131.546875,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.640625,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.734375,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.570312,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.570312,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.995245,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.081182,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.16712,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.546875,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.632813,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.71875,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380994',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380994',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 120.9375,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.03125,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.125,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 120.953125,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 120.953125,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 122.076766,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 122.162704,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 122.248641,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 120.921875,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.007813,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.09375,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380995',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380995',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 118.765625,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.851562,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.9375,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.773437,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.773437,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 119.858696,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 119.952446,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 120.046196,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.75,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.84375,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.9375,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380996',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380996',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 114.3125,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.398437,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.484375,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.328125,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.328125,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.641304,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.727242,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.813179,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.3125,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.398438,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.484375,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380997',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380997',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 121.140625,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.234375,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.328125,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.171875,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.171875,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.514266,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.600204,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.686141,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.140625,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.226563,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.3125,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380999',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380999',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 114.25,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.34375,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.4375,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.265625,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.265625,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 115.250679,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 115.344429,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 115.438179,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.234375,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.328125,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.421875,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001381000',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001381000',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 132.828125,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.90625,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.984375,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.851562,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.851562,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 134.19837,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 134.276495,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 134.35462,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.8125,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.890625,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.96875,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001381004',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001381004',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 130.734375,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.8125,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.890625,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.765625,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.765625,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.167799,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.238111,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.308424,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.734375,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.804688,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.875,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001381005',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001381005',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 126.28125,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.351562,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.421875,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.304687,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.304687,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 127.512908,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 127.58322,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 127.653533,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.265625,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.335938,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.40625,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}]
到目前为止,这是我的代码。
# # Request to get the instrumentID from CDW
listInstrumentID = []
securityPricesCDW = f"https://svc-uat-cdw/cdw/securityPrices/{dateinplay}?limit=10"
r = requests.get(securityPricesCDW).json()
# print(r)
jsonPath = parse("$..'m:assetPricing'[*].'m:pricingSource'[*].'m:instrumentId'[*].'#value'")
for match in jsonPath.find(r):
print(f"match id: {match.value}")
thisdict = match.value
listInstrumentID.append(thisdict)
无论如何,如果有人能帮我得到对象数组的所有值'instrumentId' 'm:instrumentId':[{
'#value': '100001380992',
'_instrumentIdScheme': 'mhi:MHILIST'
感谢您的任何建议
试试下面的方法(假设 data
是来自 post 的字典列表)
ids = [x['m:assetPricing'][0]['m:instrumentId'][0]['#value'] for x in data]
print(ids)
输出
['100001380992', '100001380993', '100001380994', '100001380995', '100001380996', '100001380997', '100001380999', '100001381000', '100001381004', '100001381005']
你可以试试这个:
from xml.etree import ElementTree
root = ElementTree.parse(url_of_your_file).getroot()
for found in root.findall("m:assetPricing")
print(found.find("m:instrumentId").text)
我开始使用 python,现在我正尝试从 REST 中检索一些值,但是我收到一个错误
Traceback (most recent call last):
File "h:\DESKTOP\test_check\check_securityPrices.py", line 69, in <module>
jsonPath = r["assetPricing"]["instrumentId"]
TypeError: list indices must be integers or slices, not str
这是我得到的 JSON 响应:
[{
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380992',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380992',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 141.96875,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 142.054687,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 142.140625,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 141.984375,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 141.984375,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 143.569973,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 143.65591,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 143.741848,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 141.953125,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 142.039063,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 142.125,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380993',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380993',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 131.546875,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.640625,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.734375,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.570312,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.570312,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.995245,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.081182,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.16712,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.546875,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.632813,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.71875,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380994',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380994',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 120.9375,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.03125,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.125,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 120.953125,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 120.953125,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 122.076766,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 122.162704,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 122.248641,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 120.921875,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.007813,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.09375,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380995',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380995',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 118.765625,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.851562,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.9375,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.773437,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.773437,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 119.858696,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 119.952446,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 120.046196,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.75,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.84375,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 118.9375,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380996',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380996',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 114.3125,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.398437,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.484375,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.328125,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.328125,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.641304,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.727242,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.813179,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.3125,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.398438,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.484375,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380997',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380997',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 121.140625,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.234375,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.328125,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.171875,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.171875,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.514266,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.600204,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.686141,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.140625,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.226563,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 121.3125,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001380999',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001380999',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 114.25,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.34375,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.4375,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.265625,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.265625,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 115.250679,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 115.344429,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 115.438179,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.234375,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.328125,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 114.421875,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001381000',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001381000',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 132.828125,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.90625,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.984375,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.851562,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.851562,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 134.19837,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 134.276495,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 134.35462,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.8125,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.890625,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 132.96875,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001381004',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001381004',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 130.734375,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.8125,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.890625,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.765625,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.765625,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.167799,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.238111,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 131.308424,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.734375,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.804688,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 130.875,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}, {
'_fpmlVersion': '5-6',
'header': {
'messageType': 'PrevDayCloseBond',
'sendTo': [{
'#value': 'Anvil'
}],
'creationTimestamp': '2021-09-27T06:00:00.000Z'
},
'm:asOfDate': {
'#value': '2021-09-27T00:00:00.000Z'
},
'_xmlns': 'http://www.fpml.org/FpML-5/reporting',
'_xmlns:m': 'urn:com.mizuho.bdm',
'_xmlns:mhi': 'urn:com.mizuho.bdm.mhi',
'_xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'_xsi:schemaLocation': 'http://www.fpml.org/FpML-5/reporting http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/fpml-5-6-reporting.xsd urn:com.mizuho.bdm http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/fpml/mizuho-fpml.xsd urn:com.mizuho.bdm.mhi http://svc-bdmentity01p:8080/schema/7.2.0/com/mizuho/bdm/mhi/fpml/mhi-fpml.xsd',
'm:assetPricing': [{
'm:pricingSource': [{
'#value': 'LON-XEN-BBG'
}, {
'#value': 'BGN',
'_pricingSourceScheme': 'mizuho:bloomberg-source'
}],
'm:instrumentId': [{
'#value': '100001381005',
'_instrumentIdScheme': 'mhi:MHILIST'
}, {
'#value': '100001381005',
'_instrumentIdScheme': 'mhsa:instrument-id'
}],
'm:currency': {
'#value': 'USD'
},
'm:price': [{
'value': 126.28125,
'measureType': {
'#value': 'Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.351562,
'measureType': {
'#value': 'Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.421875,
'measureType': {
'#value': 'Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.304687,
'measureType': {
'#value': 'Closing Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.304687,
'measureType': {
'#value': 'Snap Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 127.512908,
'measureType': {
'#value': 'Dirty Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 127.58322,
'measureType': {
'#value': 'Dirty Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 127.653533,
'measureType': {
'#value': 'Dirty Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.265625,
'measureType': {
'#value': 'Clean Bid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.335938,
'measureType': {
'#value': 'Clean Mid Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}, {
'value': 126.40625,
'measureType': {
'#value': 'Clean Offer Price',
'_assetMeasureScheme': 'mizuho:price-type'
}
}],
'm:pricingDate': '2021-09-27T00:00:00.000Z'
}]
}]
到目前为止,这是我的代码。
# # Request to get the instrumentID from CDW
listInstrumentID = []
securityPricesCDW = f"https://svc-uat-cdw/cdw/securityPrices/{dateinplay}?limit=10"
r = requests.get(securityPricesCDW).json()
# print(r)
jsonPath = parse("$..'m:assetPricing'[*].'m:pricingSource'[*].'m:instrumentId'[*].'#value'")
for match in jsonPath.find(r):
print(f"match id: {match.value}")
thisdict = match.value
listInstrumentID.append(thisdict)
无论如何,如果有人能帮我得到对象数组的所有值'instrumentId' 'm:instrumentId':[{ '#value': '100001380992', '_instrumentIdScheme': 'mhi:MHILIST'
感谢您的任何建议
试试下面的方法(假设 data
是来自 post 的字典列表)
ids = [x['m:assetPricing'][0]['m:instrumentId'][0]['#value'] for x in data]
print(ids)
输出
['100001380992', '100001380993', '100001380994', '100001380995', '100001380996', '100001380997', '100001380999', '100001381000', '100001381004', '100001381005']
你可以试试这个:
from xml.etree import ElementTree
root = ElementTree.parse(url_of_your_file).getroot()
for found in root.findall("m:assetPricing")
print(found.find("m:instrumentId").text)