我正在尝试解析下面的plist pl
,能够解析["IOKitPersonalities"]["UART"]["ProductFWMapping"]
中的键,但是无法打印相应的Firmware
值并遇到以下错误?我要打印所有固件值,下面还有预期的输出?
pl = {'IOKitPersonalities': {'UART': {'ProductFWMapping': {'D321': {'Firmware': 'C-4377__s-B2/aladdink.trx'}, 'J318': {'Firmware': 'C-4377__s-B2/monstrob.trx'}, 'D331': {'Firmware': 'C-4377__s-B2/geniek.trx'}}}}, 'NSHumanReadableCopyright': u'Copyright \xa9 2013 Company Inc. All rights reserved.'}
for hw in pl["IOKitPersonalities"]["UART"]["ProductFWMapping"]:
print hw
for hw in pl["IOKitPersonalities"]["UART"]["ProductFWMapping"]:
print hw['Firmware']
错误:-
print hw['Firmware']
TypeError: string indices must be integers, not str
预期输出:-
['D321','J318','D331']
['C-4377__s-B2/aladdink.trx','C-4377__s-B2/monstrob.trx','C-4377__s-B2/geniek.trx']
答案 0 :(得分:1)
硬件只是关键。应该是
for hw in pl["IOKitPersonalities"]["UART"]["ProductFWMapping"]:
print pl["IOKitPersonalities"]["UART"]["ProductFWMapping"][hw]['Firmware']