How do I parse json-object using python?

后端 未结 2 825
一个人的身影
一个人的身影 2020-12-16 01:57

I am trying to parse a json object and having problems.

import json

record= \'{\"shirt\":{\"red\":{\"quanitity\":100},\"blue\":{\"quantity\":10}},\"pants\":         


        
2条回答
  •  [愿得一人]
    2020-12-16 02:57

    import json
    
    record = '{"shirts":{"red":{"quantity":100},"blue":{"quantity":10}},"pants":{"black":{"quantity":50}}}'
    inventory = json.loads(record)
    
    for key, value in dict.items(inventory["shirts"]):
        print key, value
    
    for key, value in dict.items(inventory["pants"]):
        print key, value
    

提交回复
热议问题