count2这次获取的粉丝数量 data粉丝列表 openid ocYxcuAEy30bX0NXmGn4ypqx3tI0 ocYxcuBt0mRugKZ7tGAHPnUaOW7Y next_openidocYxcuBt0mRugKZ7tGAHPnUaOW7Y拉取列表最后一个用户的openid 怎样从上面的JSON数据中取出openid的值
可以使用以下代码从JSON数据中取出openid的值:
import json
json_data = '''{
"count":2,
"data":{
"openid":[
"ocYxcuAEy30bX0NXmGn4ypqx3tI0",
"ocYxcuBt0mRugKZ7tGAHPnUaOW7Y" ]
},
"next_openid":"ocYxcuBt0mRugKZ7tGAHPnUaOW7Y"
}'''
data = json.loads(json_data)
openid_list = data['data']['openid']
print(openid_list)
输出结果为:
['ocYxcuAEy30bX0NXmGn4ypqx3tI0', 'ocYxcuBt0mRugKZ7tGAHPnUaOW7Y']
其中,json.loads()函数用于将JSON字符串转换成Python对象。取出openid列表后,可以通过遍历列表来获取每个粉丝的openid值
原文地址: https://www.cveoy.top/t/topic/fbUz 著作权归作者所有。请勿转载和采集!