How to write a nested dictionary to json

后端 未结 1 1066
情歌与酒
情歌与酒 2021-02-12 23:41

I created a nested dictionary in Python like this:

{
 \"Laptop\": {
            \"sony\": 1
            \"apple\": 2
            \"asus\": 5
          },
 \"Came         


        
相关标签:
1条回答
  • 2021-02-13 00:21
    d = {
     "Laptop": {
                "sony": 1,
                "apple": 2,
                "asus": 5,
              },
     "Camera": {
                "sony": 2,
                "sumsung": 1,
                "nikon" : 4,
               },
    }
    with open("my.json","w") as f:
        json.dump(d,f)
    
    0 讨论(0)
提交回复
热议问题