我嘗試從 python 字典創建 JSON 的和平。不幸的是,我還無法獲得正確的格式。我的 json 物件“型別”中需要一個陣列。我怎樣才能解決這個問題?
我的代碼:
import json
association_item = {}
association_item['types']={}
association_item['types']['associationCategory'] = 'A'
association_item['types']['associationTypeId'] = '4'
我的字典:
{'types': {'associationCategory': 'A', 'associationTypeId': '4'}}
我的JSON:
{
"types": {
"associationCategory": "A",
"associationTypeId": "4"
}
}
我想要的是:
{
"types": [{
"associationCategory": "A",
"associationTypeId": "4"
}]
}
uj5u.com熱心網友回復:
您需要正確添加它,例如
association_item['types'] =
[ { 'associationCategory': 'A',
'associationTypeId': '4' } ]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/386269.html
