如何用python解析一下json对象,并将其中child_list对象中url字段和title字段拼接成同一字段{ "code": 1, "msg": "详细内容", "data": { "view": { "id": 1402206, "title": "ماندالورىيانلىقلار 3-بۆلۈم", "info": "", "user_is_vip": 0, "is_vip_ch": true, "user_is_vip_btn": "ئېچىش", "user_is_vip_tx": "ئالى ئەزا بولۇپ چەكسىز فىلىم كۆرۈڭ", "infos": "6-قىسىمغىچە يېڭىلاندى", "cat_name": "ھەرىكەتلىك", "city_name": "ئامرىكا", "age_name": "2023", "score": 9.3, "comment": 0, "up_time": "2023-04-13", "is_vip": true, "item_type": "tv", "content": "", "thumb": "http://piccdnhls.baxlan.com.cn/storage/2023/0413/2023041318003818117028000000006.jpg", "share_url": "https://www.baxlan.com/downland/", "view_one_task": "0", "view_30_menute": "0", "is_collection": "0", "actor_list": [], "director_list": [], "child_list": [ { "vid": 1402205, "item_player": 2, "title": "1-قىسىم", "free_time": 300, "org_price": "0.00", "price": "0.00", "url": "http://vodcdnhls.baxlan.com.cn/20230413/FdhFexDl/index.m3u8", "icon": 0, "type": "0" }, { "vid": 1402214, "item_player": 2, "title": "2-قىسىم", "free_time": 0, "org_price": "0.00", "price": "0.00", "url": "http://vodcdnhls.baxlan.com.cn/20230413/5X43KFtN/index.m3u8", "icon": 0, "type": "0" }, { "vid": 1403906, "item_player": 2, "title": "3-قىسىم", "free_time": 300, "org_price": "0.00", "price": "0.00", "url": "http://vodcdnhls.baxlan.com.cn/20230414/yQKGuDJB/index.m3u8", "icon": 1, "type": 1 }, { "vid": 1406593, "item_player": 2, "title": "4-قىسىم", "free_time": 300, "org_price": "0.00", "price": "0.00", "url": "http://vodcdnhls.baxlan.com.cn/20230415/2Abpzlds/index.m3u8", "icon": 1, "type": 1 }, { "vid": 1408016, "item_player": 2, "title": "5-قىسىم", "free_time": 300, "org_price": "0.00", "price": "0.00", "url": "http://vodcdnhls.baxlan.com.cn/20230416/l1u3Mqv2/index.m3u8", "icon": 1, "type": 1 }, { "vid": 1409492, "item_player": 2, "title": "6-قىسىم", "free_time": 300, "org_price": "0.00", "price": "0.00", "url": "http://vodcdnhls.baxlan.com.cn/20230417/BoDtsLsj/index.m3u8", "icon": 1, "type": 1 } ] }
时间: 2023-06-03 20:02:42 浏览: 92
可以使用json.loads()方法解析json对象,然后使用循环遍历每一个child_list中的元素,拼接url和title字段即可。示例代码如下:
```python
import json
json_str = '...' # 将json字符串替换成实际的值
json_obj = json.loads(json_str)
new_child_list = []
for child in json_obj['data']['view']['child_list']:
child['url_title'] = child['title'] + ' ' + child['url']
del child['title']
del child['url']
new_child_list.append(child)
json_obj['data']['view']['child_list'] = new_child_list
new_json_str = json.dumps(json_obj)
print(new_json_str)
```
上述代码将原始json对象中的child_list中的title和url字段拼接到一起并赋值给新字段url_title,然后删掉原有的title和url字段,最后将修改后的json对象重新转换为字符串输出。
阅读全文