简体   繁体   中英

How to parse a plist?

I am trying to parse a plist pl below, am able to parse the keys in ["IOKitPersonalities"]["UART"]["ProductFWMapping"] however am NOT able to print the corresponding Firmware values and running into below error?how do I print all the Firmware values,I have the expected output aswell below?

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']

Error:-

    print hw['Firmware']
TypeError: string indices must be integers, not str

Expected output:-

['D321','J318','D331']

['C-4377__s-B2/aladdink.trx','C-4377__s-B2/monstrob.trx','C-4377__s-B2/geniek.trx']

hw is just the key. it should be

for hw in pl["IOKitPersonalities"]["UART"]["ProductFWMapping"]:
    print pl["IOKitPersonalities"]["UART"]["ProductFWMapping"][hw]['Firmware']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM