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 + " }"