删除python中key = value模式中只有key的双引号

时间:2018-04-25 06:48:32

标签: python json

我有json数据,它以格式存储:

[{"Status": "status", "Command": "command", "IPAddress": "xx.xx.xx.xx ", "name": "name", "Service": "service"}]

我们将进一步修改以获得:

"Status="status","Command="command","IPAddress="xx.xx.xx.xx","name="name","Service="service"

但是我希望使用python脚本从键中删除双引号(")。所期望的输出如下:

Status="status",Command="command",IPAddress="xx.xx.xx.xx",name="name",Service="service"

我仍然是python的新手,非常感谢您对此有任何帮助

1 个答案:

答案 0 :(得分:1)

使用简单的迭代。

<强>实施例

j = [{"Status": "status", "Command": "command", "IPAddress": "xx.xx.xx.xx ", "name": "name", "Service": "service"}]
s = ""
for k,v in j[0].items():
    s += '{0}: "{1}", '.format(k, v)
print(s.rstrip(", "))

<强>输出:

Status: "status", IPAddress: "xx.xx.xx.xx ", Command: "command", name: "name", Service: "service"