Skip to main content
 首页 » 编程设计

python之用Python写入json文件

2025年04月02日16mayingbao

<分区>

对于一个项目,我需要用 python 编写一个 json 文件,但我已经看到的所有内容 (json.dump) 与我想做的不匹配...

我有一个结构,我只想在里面添加一些东西。 我想添加一个带有输入的服务,例如:

{ 
"Serial_011": "011", 
"Servers_011": 
    [ 
        { 
            "hostname": "srv-a.11", 
            "ipv4_address": "0.0.0.0", 
            "services": 
                [ 
                    { 
                        "uri": "http://www.google.fr/1", 
                        "expected_code": 200 
                    }, 
                    { 
                        "uri": "http://www.google.fr/2", 
                        "expected_code": 200 
                    } 
                ] 
        }, 
        { 
            "hostname": "nsc-srv-b.11", 
            "ipv4_address": "0.0.0.0", 
            "services": 
                [ 
                    { 
                        "uri": "http://www.google.fr/3", 
                        "expected_code": 200 
                    }, 
                    { 
                        "uri": "http://www.google.fr/4", 
                        "expected_code": 200 
                    } 
                ] 
        } 
    ] 
} 

提前致谢