1 回答

TA貢獻1797條經(jīng)驗 獲得超6個贊
我無法重現(xiàn)錯誤,但json.dumps
對我來說效果很好。請參考以下截圖:
我試過的代碼:
import json
JsonData={'list': {'Elements': [{'text': 'Task 1', 'Shape': 'Decision', 'id': 0},
{'text': 'Task 2', 'Shape': 'Decision', 'id': 1},
{'text': 'Task 3', 'Shape': 'Decision', 'id': 2},
{'text': 'Task 4', 'Shape': 'Decision', 'id': 3},
{'text': 'Task 5', 'Shape': 'Rectangle', 'id': 4},
{'text': 'Task 6', 'Shape': 'Decision', 'id': 5}],
'links': [{'source': 0, 'target': 1, 'key': 0},
{'source': 0, 'target': 4, 'key': 0},
{'source': 1, 'target': 2, 'key': 0},
{'source': 1, 'target': 3, 'key': 0},
{'source': 2, 'target': 1, 'key': 0},
{'source': 2, 'target': 4, 'key': 0},
{'source': 3, 'target': 1, 'key': 0},
{'source': 3, 'target': 4, 'key': 0},
{'source': 4, 'target': 5, 'key': 0},
{'source': 5, 'target': 4, 'key': 0},
{'source': 5, 'target': 1, 'key': 0}]}}
print(type(JsonData))
print(json.dumps(JsonData))
print(type(json.dumps(JsonData)))
添加回答
舉報