简体   繁体   中英

How to extract particular data from nested data structure in Python

['[{"word":"meaning","phonetics":[{"text":"/ˈmiːnɪŋ/","audio":"https://lex-audio.useremarkable.com/mp3/meaning_gb_1.mp3"}],"meanings":[{"partOfSpeech":"noun","definitions":[{"definition":"What '
 'is meant by a word, text, concept, or '
 'action.","synonyms":["definition","sense","explanation","denotation","connotation","interpretation","elucidation","explication"],"example":"the '
 'meaning of the Hindu word is ‘breakthrough, '
 'release’"}]},{"partOfSpeech":"adjective","definitions":[{"definition":"Intended '
 'to communicate something that is not directly '
 'expressed.","synonyms":["meaningful","significant","pointed","eloquent","expressive","pregnant","speaking","telltale","revealing","suggestive"]}]}]}]']

This is the format.

I wanna extract:

"meanings":[{"partOfSpeech":"noun","definitions":[{"definition":"A single distinct meaningful element of speech or writing, used with others (or sometimes alone) to form a sentence and typically shown with a space on either side when written or printed.",

How may I do it, in Python.

I believe this is what you want

import json
data = ['[{"word":"meaning","phonetics":[{"text":"/ˈmiːnɪŋ/","audio":"https://lex-audio.useremarkable.com/mp3/meaning_gb_1.mp3"}],"meanings":[{"partOfSpeech":"noun","definitions":[{"definition":"What '  'is meant by a word, text, concept, or '  'action.","synonyms":["definition","sense","explanation","denotation","connotation","interpretation","elucidation","explication"],"example":"the '  'meaning of the Hindu word is ‘breakthrough, '  'release’"}]},{"partOfSpeech":"adjective","definitions":[{"definition":"Intended '  'to communicate something that is not directly '  'expressed.","synonyms":["meaningful","significant","pointed","eloquent","expressive","pregnant","speaking","telltale","revealing","suggestive"]}]}]}]']
json_data = json.loads(data[0])
meanings = json_data[0]['meanings']
print(meanings)
# [{'partOfSpeech': 'noun', 'definitions': [{'definition': 'What is meant by a word, text, concept, or action.', 'synonyms': ['definition', 'sense', 'explanation', 'denotation', 'connotation', 'interpretation', 'elucidation', 'explication'], 'example': 'the meaning of the Hindu word is ‘breakthrough, release’'}]}, {'partOfSpeech': 'adjective', 'definitions': [{'definition': 'Intended to communicate something that is not directly expressed.', 'synonyms': ['meaningful', 'significant', 'pointed', 'eloquent', 'expressive', 'pregnant', 'speaking', 'telltale', 'revealing', 'suggestive']}]}]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM