0
我有元組的列表,並希望從中從一個元組和按鍵的單獨列表值的列表創建一個JSON字典
[(1, 'a', 'A'), (2, 'b', 'B'), (3, 'c', 'C'), (4, 'd', 'D'), (5, 'e', 'E'), (6, 'f', 'F'), (7, 'g', 'G'), (8, 'h', 'H'), (9, 'i', 'I')]
和預期JSON使JSON
{
"List": [
{
"name": "1",
"description": "a",
"type": "A"
},
{
"name": "2",
"description": "b",
"type": "B"
},
{
"name": "3",
"description": "c",
"type": "C"
},
and so on....
]
}
我該怎麼做?
重複的確定的答案沒有工作,給了這個錯誤
ValueError: dictionary update sequence element #0 has length 3; 2 is required
[從元組列表中格式化JSON字符串的更多pythonic方法]的可能重複(http://stackoverflow.com/questions/13761054/more-pythonic-way-to-format-a-json-string-from-元組列表) – Serenity
沒有工作,給出了錯誤ValueError:字典更新序列元素#0的長度爲3; 2是必需的 – x0v
他可能只是讀你的標題,這聽起來像你想要做的是提名的副本。我會爲你編輯你的標題。 – tripleee