Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

{
    "1":"文去",
    "2":"147",
}

需要改成

[
    {
        "name": "1", 
        "value": "文去"
    }, 
    {
        "name": "2", 
        "value": "147"
    }
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
344 views
Welcome To Ask or Share your Answers For Others

1 Answer

思路:取出字典中的key,value组成新的res_dic,将res_dic作为res_list中的项append进list中。

res_list = []
res_dic = {}
for k,v in dic.items():
    res_dic = {
        'name':v,
        'value':k
        }
    res_list.append(res_dic)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...