第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

json 數(shù)組轉(zhuǎn)換為 json 數(shù)組 - Python

json 數(shù)組轉(zhuǎn)換為 json 數(shù)組 - Python

一只名叫tom的貓 2022-12-27 14:48:21
在有效載荷發(fā)生變化之前,我的代碼運行良好。field_types =   [  ('subject', str),  ('type', str)]#reading a raw csv fileoutput = []with open('file.csv','r',encoding = 'utf-8-sig') as f:    for row in csv.DictReader(f):        row.update((key, conversion(row[key]))        for key, conversion in field_types)        output.append(row)    with open('file.json','w') as outfile: #storing records as json        json.dump(output,outfile,sort_keys = True, indent = 4)結(jié)果保存的很好:    {        "subject": "1",        "type": "2"    },    {        "subject": "1",        "type": "3"    }]當前要求它應該保存為 ie 我猜是數(shù)組中的 jsonarray。你有過這種情況嗎?如何實現(xiàn)?    {        "subject":        {            "id": "1"            },        "type": "2"    },    {        "subject":             {            "id": "1"            },        "type": "3"    }]
查看完整描述

1 回答

?
四季花海

TA貢獻1811條經(jīng)驗 獲得超5個贊

這應該做的工作:


def str2dict(s):

    return dict(id=s)


field_types =   [

  ('subject', str2dict),

  ('type', str)

]


查看完整回答
反對 回復 2022-12-27
  • 1 回答
  • 0 關(guān)注
  • 109 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號