Python - 分析牛津词典API JSON输出(Python - Parsing Oxford Dictionary API JSON Output)
我想从下面的json输出中提取第一个定义值。 此外,还可以逐行打印所有的定义值。
{ "metadata": { "provider": "Oxford University Press" }, "results": [ { "id": "ace", "language": "en", "lexicalEntries": [ { "entries": [ { "etymologies": [ "Middle English (denoting the âoneâ on dice): via Old French from Latin as âunity, a unitâ" ], "grammaticalFeatures": [ { "text": "Singular", "type": "Number" } ], "homographNumber": "100", "senses": [ { "definitions": [ "a playing card with a single spot on it, ranked as the highest card in its suit in most card games" ], "domains": [ "Cards" ], "examples": [ { "registers": [ "figurative" ], "text": "life had started dealing him aces again" }, { "text": "the ace of diamonds" } ], "id": "m_en_gbus0005680.006", "short_definitions": [ "playing card with single spot on it, ranked as highest card in its suit in most card games" ] }, { "definitions": [ "a person who excels at a particular sport or other activity" ], "domains": [ "Sport" ], "examples": [ { "text": "a motorcycle ace" } ], "id": "m_en_gbus0005680.010", "registers": [ "informal" ], "short_definitions": [ "person who excels at particular sport or other activity" ], "subsenses": [ { "definitions": [ "a pilot who has shot down many enemy aircraft" ], "domains": [ "Air Force" ], "examples": [ { "text": "a Battle of Britain ace" } ], "id": "m_en_gbus0005680.011", "short_definitions": [ "pilot who has shot down many enemy aircraft" ] } ], "thesaurusLinks": [ { "entry_id": "ace", "sense_id": "t_en_gb0000173.001" } ] }, { "definitions": [ "(in tennis and similar games) a service that an opponent is unable to return and thus wins a point" ], "domains": [ "Tennis" ], "examples": [ { "text": "Nadal banged down eight aces in the set" } ], "id": "m_en_gbus0005680.013", "short_definitions": [ "(in tennis and similar games) service that opponent is unable to return and thus wins point" ], "subsenses": [ { "definitions": [ "a hole in one" ], "domains": [ "Golf" ], "examples": [ { "text": "his hole in one at the 15th was Senior's second ace as a professional" } ], "id": "m_en_gbus0005680.014", "registers": [ "informal" ], "short_definitions": [ "hole in one" ] } ] } ] }, { "etymologies": [ "early 21st century: abbreviation of asexual, with alteration of spelling on the model of ace" ], "grammaticalFeatures": [ { "text": "Singular", "type": "Number" } ], "homographNumber": "200", "senses": [ { "definitions": [ "a person who has no sexual feelings or desires" ], "domains": [ "Sex" ], "examples": [ { "text": "both asexual, they have managed to connect with other aces offline" } ], "id": "m_en_gbus1190638.004", "short_definitions": [ "asexual person" ] } ] } ], "language": "en", "lexicalCategory": "Noun", "pronunciations": [ { "audioFile": "http://audio.oxforddictionaries.com/en/mp3/ace_1_gb_1_abbr.mp3", "dialects": [ "British English" ], "phoneticNotation": "IPA", "phoneticSpelling": "eɪs" } ], "text": "ace" }, { "entries": [ { "grammaticalFeatures": [ { "text": "Positive", "type": "Degree" } ], "homographNumber": "101", "senses": [ { "definitions": [ "very good" ], "examples": [ { "text": "Ace! You've done it!" }, { "text": "an ace swimmer" } ], "id": "m_en_gbus0005680.016", "registers": [ "informal" ], "short_definitions": [ "very good" ], "thesaurusLinks": [ { "entry_id": "ace", "sense_id": "t_en_gb0000173.002" } ] } ] }, { "grammaticalFeatures": [ { "text": "Positive", "type": "Degree" } ], "homographNumber": "201", "senses": [ { "definitions": [ "(of a person) having no sexual feelings or desires; asexual" ], "domains": [ "Sex" ], "examples": [ { "text": "I didn't realize that I was ace for a long time" } ], "id": "m_en_gbus1190638.006", "short_definitions": [ "asexual" ] } ] } ], "language": "en", "lexicalCategory": "Adjective", "pronunciations": [ { "audioFile": "http://audio.oxforddictionaries.com/en/mp3/ace_1_gb_1_abbr.mp3", "dialects": [ "British English" ], "phoneticNotation": "IPA", "phoneticSpelling": "eɪs" } ], "text": "ace" }, { "entries": [ { "grammaticalFeatures": [ { "text": "Transitive", "type": "Subcategorization" }, { "text": "Present", "type": "Tense" } ], "homographNumber": "102", "senses": [ { "definitions": [ "(in tennis and similar games) serve an ace against (an opponent)" ], "domains": [ "Tennis" ], "examples": [ { "text": "he can ace opponents with serves of no more than 62 mph" } ], "id": "m_en_gbus0005680.020", "registers": [ "informal" ], "short_definitions": [ "(in tennis and similar games) serve ace against" ], "subsenses": [ { "definitions": [ "score an ace on (a hole) or with (a shot)" ], "domains": [ "Golf" ], "examples": [ { "text": "there was a prize for the first player to ace the hole" } ], "id": "m_en_gbus0005680.026", "short_definitions": [ "score ace on hole or with" ] } ] }, { "definitions": [ "achieve high marks in (a test or exam)" ], "examples": [ { "text": "I aced my grammar test" } ], "id": "m_en_gbus0005680.028", "regions": [ "North American" ], "registers": [ "informal" ], "short_definitions": [ "achieve high marks in" ], "subsenses": [ { "definitions": [ "outdo someone in a competitive situation" ], "examples": [ { "text": "the magazine won an award, acing out its rivals" } ], "id": "m_en_gbus0005680.029", "notes": [ { "text": "\"ace someone out\"", "type": "wordFormNote" } ], "short_definitions": [ "outdo someone in competitive situation" ] } ] } ] } ], "language": "en", "lexicalCategory": "Verb", "pronunciations": [ { "audioFile": "http://audio.oxforddictionaries.com/en/mp3/ace_1_gb_1_abbr.mp3", "dialects": [ "British English" ], "phoneticNotation": "IPA", "phoneticSpelling": "eɪs" } ], "text": "ace" } ], "type": "headword", "word": "ace" } ]
我正在阅读这样的输出:
oxford_dict = json.loads(oxford_output) print(oxford_dict['metadata']['provider'])
但我不确定如何进一步钻取并获取第一个定义,因为它存在多次。
I would like to extract the first definition value from the following json output. Additionally, it would also be nice to print all of the definition values line by line.
{ "metadata": { "provider": "Oxford University Press" }, "results": [ { "id": "ace", "language": "en", "lexicalEntries": [ { "entries": [ { "etymologies": [ "Middle English (denoting the âoneâ on dice): via Old French from Latin as âunity, a unitâ" ], "grammaticalFeatures": [ { "text": "Singular", "type": "Number" } ], "homographNumber": "100", "senses": [ { "definitions": [ "a playing card with a single spot on it, ranked as the highest card in its suit in most card games" ], "domains": [ "Cards" ], "examples": [ { "registers": [ "figurative" ], "text": "life had started dealing him aces again" }, { "text": "the ace of diamonds" } ], "id": "m_en_gbus0005680.006", "short_definitions": [ "playing card with single spot on it, ranked as highest card in its suit in most card games" ] }, { "definitions": [ "a person who excels at a particular sport or other activity" ], "domains": [ "Sport" ], "examples": [ { "text": "a motorcycle ace" } ], "id": "m_en_gbus0005680.010", "registers": [ "informal" ], "short_definitions": [ "person who excels at particular sport or other activity" ], "subsenses": [ { "definitions": [ "a pilot who has shot down many enemy aircraft" ], "domains": [ "Air Force" ], "examples": [ { "text": "a Battle of Britain ace" } ], "id": "m_en_gbus0005680.011", "short_definitions": [ "pilot who has shot down many enemy aircraft" ] } ], "thesaurusLinks": [ { "entry_id": "ace", "sense_id": "t_en_gb0000173.001" } ] }, { "definitions": [ "(in tennis and similar games) a service that an opponent is unable to return and thus wins a point" ], "domains": [ "Tennis" ], "examples": [ { "text": "Nadal banged down eight aces in the set" } ], "id": "m_en_gbus0005680.013", "short_definitions": [ "(in tennis and similar games) service that opponent is unable to return and thus wins point" ], "subsenses": [ { "definitions": [ "a hole in one" ], "domains": [ "Golf" ], "examples": [ { "text": "his hole in one at the 15th was Senior's second ace as a professional" } ], "id": "m_en_gbus0005680.014", "registers": [ "informal" ], "short_definitions": [ "hole in one" ] } ] } ] }, { "etymologies": [ "early 21st century: abbreviation of asexual, with alteration of spelling on the model of ace" ], "grammaticalFeatures": [ { "text": "Singular", "type": "Number" } ], "homographNumber": "200", "senses": [ { "definitions": [ "a person who has no sexual feelings or desires" ], "domains": [ "Sex" ], "examples": [ { "text": "both asexual, they have managed to connect with other aces offline" } ], "id": "m_en_gbus1190638.004", "short_definitions": [ "asexual person" ] } ] } ], "language": "en", "lexicalCategory": "Noun", "pronunciations": [ { "audioFile": "http://audio.oxforddictionaries.com/en/mp3/ace_1_gb_1_abbr.mp3", "dialects": [ "British English" ], "phoneticNotation": "IPA", "phoneticSpelling": "eɪs" } ], "text": "ace" }, { "entries": [ { "grammaticalFeatures": [ { "text": "Positive", "type": "Degree" } ], "homographNumber": "101", "senses": [ { "definitions": [ "very good" ], "examples": [ { "text": "Ace! You've done it!" }, { "text": "an ace swimmer" } ], "id": "m_en_gbus0005680.016", "registers": [ "informal" ], "short_definitions": [ "very good" ], "thesaurusLinks": [ { "entry_id": "ace", "sense_id": "t_en_gb0000173.002" } ] } ] }, { "grammaticalFeatures": [ { "text": "Positive", "type": "Degree" } ], "homographNumber": "201", "senses": [ { "definitions": [ "(of a person) having no sexual feelings or desires; asexual" ], "domains": [ "Sex" ], "examples": [ { "text": "I didn't realize that I was ace for a long time" } ], "id": "m_en_gbus1190638.006", "short_definitions": [ "asexual" ] } ] } ], "language": "en", "lexicalCategory": "Adjective", "pronunciations": [ { "audioFile": "http://audio.oxforddictionaries.com/en/mp3/ace_1_gb_1_abbr.mp3", "dialects": [ "British English" ], "phoneticNotation": "IPA", "phoneticSpelling": "eɪs" } ], "text": "ace" }, { "entries": [ { "grammaticalFeatures": [ { "text": "Transitive", "type": "Subcategorization" }, { "text": "Present", "type": "Tense" } ], "homographNumber": "102", "senses": [ { "definitions": [ "(in tennis and similar games) serve an ace against (an opponent)" ], "domains": [ "Tennis" ], "examples": [ { "text": "he can ace opponents with serves of no more than 62 mph" } ], "id": "m_en_gbus0005680.020", "registers": [ "informal" ], "short_definitions": [ "(in tennis and similar games) serve ace against" ], "subsenses": [ { "definitions": [ "score an ace on (a hole) or with (a shot)" ], "domains": [ "Golf" ], "examples": [ { "text": "there was a prize for the first player to ace the hole" } ], "id": "m_en_gbus0005680.026", "short_definitions": [ "score ace on hole or with" ] } ] }, { "definitions": [ "achieve high marks in (a test or exam)" ], "examples": [ { "text": "I aced my grammar test" } ], "id": "m_en_gbus0005680.028", "regions": [ "North American" ], "registers": [ "informal" ], "short_definitions": [ "achieve high marks in" ], "subsenses": [ { "definitions": [ "outdo someone in a competitive situation" ], "examples": [ { "text": "the magazine won an award, acing out its rivals" } ], "id": "m_en_gbus0005680.029", "notes": [ { "text": "\"ace someone out\"", "type": "wordFormNote" } ], "short_definitions": [ "outdo someone in competitive situation" ] } ] } ] } ], "language": "en", "lexicalCategory": "Verb", "pronunciations": [ { "audioFile": "http://audio.oxforddictionaries.com/en/mp3/ace_1_gb_1_abbr.mp3", "dialects": [ "British English" ], "phoneticNotation": "IPA", "phoneticSpelling": "eɪs" } ], "text": "ace" } ], "type": "headword", "word": "ace" } ]
I'm reading that output with something like this:
oxford_dict = json.loads(oxford_output) print(oxford_dict['metadata']['provider'])
But I'm not really sure how to drill down further and grab the first definition, since it exists multiple times.
原文:https://stackoverflow.com/questions/50196887
最满意答案
就在这里。 我从来没有尝试过,所以我不能证实这实际上可行,但...
javac -proc:only
意味着只有注释处理完成,不需要任何后续编译。
如果这不起作用,那么刚使用时会出现什么问题
javac -d /dev/null
Yes, there is. I have never tried it, so I can not verify that this actually works, but ...
javac -proc:only
means that only annotation processing is done, without any subsequent compilation.
If that did not work, what is wrong with just using
javac -d /dev/null
相关问答
更多-
Javac - 终极论点?(Javac - terminal arguments?)[2023-05-23]
使用javac编译时,不会传递应用程序参数。 在指定要运行的类之后 , 在使用java运行它们时,在命令行上传递它们: javac MyApp.java java MyApp --port=47000 这是Java关于命令行参数的教程 。 You don't pass your application arguments when you compile with javac. You pass them on the command line when running them with java, a ... -
就在这里。 我从来没有尝试过,所以我不能证实这实际上可行,但... javac -proc:only 意味着只有注释处理完成,不需要任何后续编译。 如果这不起作用,那么刚使用时会出现什么问题 javac -d /dev/null Yes, there is. I have never tried it, so I can not verify that this actually works, but ... javac -proc:only means that only annotation proce ...
-
使用javac导入(Using javac with import)[2019-12-30]
package java.io是核心java的一部分,你不必在你的类路径中添加任何额外的东西 package java.io is part of core java, you do not have to put anything extra into your classpath -
我如何看到IntelliJ IDEA用来编译我的代码的javac命令?(How can I see the javac command IntelliJ IDEA uses to compile my code?)[2022-01-22]
IntelliJ IDEA不运行javac ,因此你看不到命令行。 编译器API直接来自Java代码。 如果您为build.log文件启用调试日志记录 ,则可以找到更多详细信息,修改和相关文件如何编译以及使用哪些选项。 示例调试日志行: [ 41011] DEBUG - s.incremental.java.JavaBuilder - Compiling chunk [stopme] with options: "-g -deprecation -proceedOnError -encoding UTF ... -
用javac选择方法(selecting methods with javac)[2024-02-28]
执行Java程序只会执行main方法。 如果您的程序中需要用户交互功能,则需要在main方法中考虑这一点。 考虑一下Scanner类,它允许用户通过提供输入与程序进行交互。 您还可以将名为args的String[]数组传递给可以解析的main方法,但这种交互只在运行时开始时发生一次 Executing a Java program will only execute the main method. If you need user interactive functionality in your pro ... -
Javac用于编译java代码。 如果您注意到WordCount示例,则有许多import语句要求您在类路径中添加相应的jar。 当你运行hadoop com.sun.tools.javac.Main WordCount.java ,hadoop已经加载了所有这些依赖的jar来编译你的程序。 您可以通过运行javac WordCount.java来测试它,如果您的类路径中还没有这些必需的jar,编译器会抛出cannot find symbol错误 Javac is used for compiling yo ...
-
很可能你的javac只需要比默认值更多的内存。 代码越复杂,它使用的内存就越多。 这不太可能是一个错误,或者因为你使用了错误的JAR。 我会确保你使用最新的更新,以防这是一个已修复的问题,但这不太可能有所作为。 Most likely your javac just needs more memory than the default. The more complex the code, the more memory it uses. This is unlikely to be a bug or be ...
-
RUN命令仅在容器的文件系统上运行,而不是在主机的文件系统上运行。 您必须将文件从本地文件系统复制到容器的文件系统: FROM jboss/wildfly COPY src /src RUN javac /src/Hello.java 许多开发人员发现他们想要将他们的构建容器与运行容器分开。 运行软件的容器对其环境的要求通常比构建容器要少得多(例如,没有安装JDK,只有JRE)。 为此你的构建容器将是: FROM openjdk:8 COPY src /src RUN javac /src/Hello.j ...
-
根据文档( Java 5 , Java 6 ),当您按照交叉编译示例中的说明操作时,Oracle SDK应该能够执行此操作。 Java 6应支持1.3到1.6之间的任何版本作为-target ; 它不会说当你在源代码中使用泛型和其他“兼容”功能时会发生什么。 编译器应该能够剥离它们。 游戏中的另一个罪魁祸首可能是javac : 编译器可能能够处理这组参数,但命令行工具可能会冒犯。 在这种情况下,使用Java Compiler API编写自己的命令行。 这可能会带来一些你无法实现的技巧。 您也可以尝试Ecli ...
-
您可以尝试将此选项传递给javac(除了-cp): -Djava.ext.dirs=$DIR/lib 避免查看$ JAVA_HOME中的扩展名。 似乎-cp不会覆盖它。 You might try and pass this option to javac (in addition to the -cp): -Djava.ext.dirs=$DIR/lib to avoid looking at the extensions in $JAVA_HOME. It seems that -cp does n ...