json格式
程序员文章站
2024-01-13 11:43:10
...
0 字符串要""包裹
1 单个对象要在{} 中
2 多个对象要在[ {1}, {2}, {3}, {4}] 中
def toJson(self):
"""
将图保存为json格式
:return:
"""
id = " \"id\" : " + "\"" + self.id + "\""
loc = "\"loc\" : " + "\"" + self.long + "_" + self.lat + "\""
adjacent = "\"adjacent\" : ["
for v, v_weight in self.adjacent.items():
adjacent += "{ " + "\"adj_id\" : " + "\"" + str(v.id) + "\"" + "," \
+ "\"loc\" : " + "\"" + v.long + "_" + v.lat + "\"" + "," \
+ "\"weight\" : " + str(v_weight) + "} ,"
adjacent = adjacent.rstrip(",") + ' ]'
return "{" + id + ", " + loc + ", " + adjacent + " }"
上一篇: 数据显示 中国APP正在失去印度应用市场的绝对优势
下一篇: 摩托罗拉折叠屏手机细节曝光:年底发售