0
私は以下のjson文字列を持っています。時には、複数の定義要素があり、時には1つしかないこともあります。私はJSONの構文解析に慣れていないので、何らかの形で非常に原始的なやり方で、発生する最初の定義要素の値を得ることができました。しかし、私はオンラインで見つけることができるリソースがないので、定義のすべての価値を得ることができません。 2番目の出来事が存在するかどうかを確認する必要がありますか、それとももっと良い方法がありますか?JSONの解析中に要素が存在するかどうかを確認するにはどうすればよいですか?
JSON:
{
"metadata": {
"provider": "Oxford University Press"
},
"results": [
{
"id": "edifice",
"language": "en",
"lexicalEntries": [
{
"entries": [
{
"etymologies": [
"late Middle English: via Old French from Latin aedificium, from aedis dwelling + facere make"
],
"grammaticalFeatures": [
{
"text": "Singular",
"type": "Number"
}
],
"senses": [
{
"definitions": [
"a large, imposing building."
],
"id": "m_en_gb0256160.001",
"registers": [
"formal"
]
},
{
"definitions": [
"a complex system of beliefs:"
],
"examples": [
{
"text": "the concepts on which the edifice of capitalism was built"
}
],
"id": "m_en_gb0256160.002",
"registers": [
"formal"
]
}
]
}
],
"language": "en",
"lexicalCategory": "Noun",
"pronunciations": [
{
"audioFile": "http://audio.oxforddictionaries.com/en/mp3/edifice_gb_1.mp3",
"dialects": [
"British English"
],
"phoneticNotation": "IPA",
"phoneticSpelling": "ˈɛdɪfɪs"
}
],
"text": "edifice"
}
],
"type": "headword",
"word": "edifice"
}
]
}
Javaが定義値を取得するスニペット:
String locations = data.getJSONArray("results").getJSONObject(0).getJSONArray("lexicalEntries").getJSONObject(0).getJSONArray("entries").getJSONObject(0).getJSONArray("senses").getJSONObject(0).get("definitions").toString();
それは働いた。これは私がオンラインで見つけたAPIです。ありがとう。乾杯 –