我在 Python 中有这本字典:
[('157.55.39.64', 4), ('188.165.15.192', 2), ('1.165.15.192', 1)]
Run Code Online (Sandbox Code Playgroud)
其中第一个字段是 IP 地址,另一个字段表示文件中出现的次数。
我想有一个像这样的json表示:
[{"ip":"157.55.39.64","times":4},
{"ip":"188.165.15.192","times":2},
{"ip":"1.165.15.192","times":1}]
Run Code Online (Sandbox Code Playgroud)
我尝试使用 jsonify(dictionary),但我得到了这个:
{"157.55.39.64":4, "188.165.15.192": 2, "1.165.15.192":1}
Run Code Online (Sandbox Code Playgroud)
这只是一个 json 项目。我不知道如何将字符串“ip”和“times”放在 json 文件中。
有什么帮助吗?