在这个包含10个JSON的字典中,我只想打印文本、标题、url和TextualRating。我有点困惑,因为嵌套的字典。
我如何循环所有这些,并只打印选定的参数我们为他们全部(文本,标题,url和TextualRating)
Json查看者照片:这是Json美丽的照片
Json代码:
{“声明”:“苹果AirPods破坏你的健康,发射的辐射是耳机的5倍,辐射比微波炉多”,“索赔人”:“社交媒体用户”,“声明日期”:‘2022-05-01T00:00:00:00Z’,‘评论’:{'publisher':{'name':‘美国之今’,'usatoday.com'} },‘'url':'https://www.usatoday.com/story/news/factcheck/2022/08/10/fact-check-context-missing-claim-health-effects-airpods/9661778002/','title':’事实检查:声称AirPods和其他蓝牙耳机的健康影响‘,'reviewDate':'2022-08-11T01:33:14Z',’文本分析‘:’缺失上下文‘,’语言代码‘:'en'}},{'text':’‘,“索赔人”:“脸book.com”,“声明”:“2022-07-01T20:40:00Z”,“声明评论”:{“出版商”:{“名称”:“铅故事”,“站点”:“leadstories.com”},“url”:'https://leadstories.com/hoax-alert/2022/07/fact-check-apple-logo-is-not-honoring-inventor-alan-turing-who-may-have-died-by-poisoned-apple.html',“标题”:“事实查证:苹果Logo没有表彰可能死于苹果中毒的发明者艾伦图灵”、“评论日期”:“2022-07-01T20:40:00Z”、“文本分析”:“城市传说”、“语言代码”:“en”}、{“文本”:“来自苹果AirPods危险的辐射”、“申索人”:“社交媒体用户”、“声明评论”:{ {'publisher':{'name':‘thip.media’、‘thip.media’}、'thip.media'},‘'url':'https://www.thip.media/health-news-fact-check/fact-check-is-radiation-from-apple-airpods-dangerous/30863/','title':’事实检查:来自苹果AirPods的辐射危险吗?‘、'reviewDate':’2022-0504T00:00:00Z‘、’大部分错误‘、’语言代码‘:’en‘}}、'nextPageToken':’CAM‘}’‘。
发布于 2022-08-26 23:57:31
我希望你的json结构如下,
{'claims': [{
'text': 'Apple AirPods destroy your health, emit 5 times more radiation than over-ear headphones and emit "more radiation than a microwave"',
'claimant': 'Social media users', 'claimDate': '2022-05-01T00:00:00Z', 'claimReview': [
{'publisher': {'name': 'USA Today', 'site': 'usatoday.com'},
'url': 'https://www.usatoday.com/story/news/factcheck/2022/08/10/fact-check-context-missing-claim-health-effects-airpods/9661778002/',
'title': 'Fact check: Claim about health effects of AirPods and other Bluetooth earphones is missing context',
'reviewDate': '2022-08-11T01:33:14Z', 'textualRating': 'Missing Context', 'languageCode': 'en'}]},
{'text': 'Apple Logo Alan Turing Death', 'claimant': 'facebook.com',
'claimDate': '2022-07-01T20:40:00Z', 'claimReview': [
{'publisher': {'name': 'Lead Stories', 'site': 'leadstories.com'},
'url': 'https://leadstories.com/hoax-alert/2022/07/fact-check-apple-logo-is-not-honoring-inventor-alan-turing-who-may-have-died-by-poisoned-apple.html',
'title': 'Fact Check: Apple Logo Is NOT Honoring Inventor Alan Turing Who May Have Died By Poisoned Apple',
'reviewDate': '2022-07-01T20:40:00Z', 'textualRating': 'Urban Legend', 'languageCode': 'en'}]},
{'text': 'Radiation from Apple AirPods dangerous', 'claimant': 'Social media user', 'claimReview': [
{'publisher': {'name': 'THIP Media', 'site': 'thip.media'},
'url': 'https://www.thip.media/health-news-fact-check/fact-check-is-radiation-from-apple-airpods-dangerous/30863/',
'title': 'Fact Check: Is radiation from Apple AirPods dangerous?',
'reviewDate': '2022-05-04T00:00:00Z', 'textualRating': 'Mostly False', 'languageCode': 'en'}]}],
'nextPageToken': 'CAM'}
在这种情况下,您可以使用以下代码提取值的形式键,
claims_json_data = {'claims': [{
'text': 'Apple AirPods destroy your health, emit 5 times more radiation than over-ear headphones and emit "more radiation than a microwave"',
'claimant': 'Social media users', 'claimDate': '2022-05-01T00:00:00Z', 'claimReview': [
{'publisher': {'name': 'USA Today', 'site': 'usatoday.com'},
'url': 'https://www.usatoday.com/story/news/factcheck/2022/08/10/fact-check-context-missing-claim-health-effects-airpods/9661778002/',
'title': 'Fact check: Claim about health effects of AirPods and other Bluetooth earphones is missing context',
'reviewDate': '2022-08-11T01:33:14Z', 'textualRating': 'Missing Context', 'languageCode': 'en'}]},
{'text': 'Apple Logo Alan Turing Death', 'claimant': 'facebook.com',
'claimDate': '2022-07-01T20:40:00Z', 'claimReview': [
{'publisher': {'name': 'Lead Stories', 'site': 'leadstories.com'},
'url': 'https://leadstories.com/hoax-alert/2022/07/fact-check-apple-logo-is-not-honoring-inventor-alan-turing-who-may-have-died-by-poisoned-apple.html',
'title': 'Fact Check: Apple Logo Is NOT Honoring Inventor Alan Turing Who May Have Died By Poisoned Apple',
'reviewDate': '2022-07-01T20:40:00Z', 'textualRating': 'Urban Legend', 'languageCode': 'en'}]},
{'text': 'Radiation from Apple AirPods dangerous', 'claimant': 'Social media user', 'claimReview': [
{'publisher': {'name': 'THIP Media', 'site': 'thip.media'},
'url': 'https://www.thip.media/health-news-fact-check/fact-check-is-radiation-from-apple-airpods-dangerous/30863/',
'title': 'Fact Check: Is radiation from Apple AirPods dangerous?',
'reviewDate': '2022-05-04T00:00:00Z', 'textualRating': 'Mostly False', 'languageCode': 'en'}]}],
'nextPageToken': 'CAM'}
for claim in claims_json_data['claims']:
print(f"text: {claim['text']}")
for review in claim['claimReview']:
print(f"url: {review['url']}")
print(f"title: {review['title']}")
print(f"textualRating {review['textualRating']}")
print('\n')
https://stackoverflow.com/questions/73507385
复制相似问题