python循环给字典,对象添加键值

代码:

            if user_actions_name:
                # 获取自定义事件详情
                print('---------自定义事件名---------')
                print(user_actions_name)
                new_custom_item = []
                for w in data:
                    custom_name = json.loads(w['custom_data'])
                    if custom_name['cutomName'] == user_actions_name:
                        print('---------自定义事件里的List---------')
                        print(custom_name['eventdata']['list'])
                        new_custom_item2 = {}
                        for list_key in custom_name['eventdata']['list']:
                            print('---------自定义事件里的List里边的条目---------')
                            print(list_key)
                            # new_custom_item.append({list_key['key']: list_key['value']})
                            new_custom_item2[list_key['key']] = list_key['value']
                        new_custom_item.append(new_custom_item2)
                print('--------新合成的用户行为数据')
                print(type(new_custom_item))
                print(new_custom_item)
                return SuccessResponse(data=new_custom_item, msg="获取成功")

 

打印:

[{'名字': '韩梅梅', '动作': '跳舞'}, {'名字': '韩梅梅1', '动作': '跳舞1'}]

  

  

posted @ 2022-11-14 21:41  门徒21  阅读(252)  评论(0)    收藏  举报