I'm trying to loop around a structured string or list to extract data but I always end up with Type Error or Value error. I tried to convert it to JSON but with the same results. Here is the string:
I want to extract the corresponding data to the values untagged_vlan, tagged_vlan, port_name and port_number. Is there any way to convert this string into slices so I can loop around them and extract the required data?
Thanks in advance
[[{'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"01-01-140"', 'port_no': '1'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"02-01-142"', 'port_no': '2'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"03-01-144"', 'port_no': '3'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"04-01-146"', 'port_no': '4'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"05-01-148"', 'port_no': '5'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"06-01-150"', 'port_no': '6'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"07-01-151"', 'port_no': '7'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"08-01-152"', 'port_no': '8'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"09-01-153"', 'port_no': '9'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"10-01-155"', 'port_no': '10'}]]
question from:
https://stackoverflow.com/questions/65648414/how-to-access-and-extract-data-from-structured-string-or-list-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…