{ "1":"文去", "2":"147", }
needs to be changed to
[ { "name": "1", "value": "文去" }, { "name": "2", "value": "147" } ]
Idea: Take out the key and value in the dictionary to form a new res_dic, and append res_dic to the list as an item in res_list.
res_list = [] res_dic = {} for k,v in dic.items(): res_dic = { 'name':v, 'value':k } res_list.append(res_dic)
Idea: Take out the key and value in the dictionary to form a new res_dic, and append res_dic to the list as an item in res_list.