JSON을 매우 처음 사용했습니다. json-lib를 사용하여 옥스포드 사전 API에 의해이 JSON 응답에서 "정의"를 얻으려고 노력했습니다. 모든 종류의 것을 시도했다. 그러나 "결과"의 모든 것보다 더 구체적인 것을 얻을 수는 없습니다. 이것이 왜 그렇게 어려운지 알아 내고 싶습니다. 그렇지 않으면 정규 표현식에 의지 할 것입니다.사전 API에서 Java로 JSON 구문 분석
JSONObject obj = new JSONObject(stringBuilder.toString());
JSONArray arr = obj.getJSONArray("results");
String test = arr.getJSONObject(1).toString(); // Empty wtf?
String definition = obj.getString("definitions"); // empty also...
는 "ID", "언어"와 "lexicalEntries"에 접근을 관리 별도로,하지만 이외에는 아무 것도 협력 할 것 같지 않습니다 ....이 정상적인 JSON 응답인가? 꽤 어색해? 감사합니다 ...
JSON :
{
"metadata": {
"provider": "Oxford University Press"
},
"results": [
{
"id": "ace",
"language": "en",
"lexicalEntries": [
{
"entries": [
{
"homographNumber": "000",
"senses": [
{
"definitions": [
"a playing card with a single spot on it, ranked as the highest card in its suit in most card games"
],
"id": "m_en_gbus0005680.006"
},
{
"definitions": [
"a person who excels at a particular sport or other activity"
],
"id": "m_en_gbus0005680.010",
"subsenses": [
{
"definitions": [
"a pilot who has shot down many enemy aircraft"
],
"id": "m_en_gbus0005680.011"
}
]
},
{
"definitions": [
"(in tennis and similar games) a service that an opponent is unable to return and thus wins a point"
],
"id": "m_en_gbus0005680.013",
"subsenses": [
{
"definitions": [
"a hole in one"
],
"id": "m_en_gbus0005680.014"
}
]
}
]
}
],
"language": "en",
"lexicalCategory": "Noun",
"text": "ace"
},
{
"entries": [
{
"homographNumber": "001",
"senses": [
{
"definitions": [
"very good"
],
"id": "m_en_gbus0005680.016"
}
]
}
],
"language": "en",
"lexicalCategory": "Adjective",
"text": "ace"
},
{
"entries": [
{
"homographNumber": "002",
"senses": [
{
"definitions": [
"(in tennis and similar games) serve an ace against (an opponent)"
],
"id": "m_en_gbus0005680.020",
"subsenses": [
{
"definitions": [
"score an ace on (a hole) or with (a shot)"
],
"id": "m_en_gbus0005680.026"
}
]
},
{
"definitions": [
"achieve high marks in (a test or exam)"
],
"id": "m_en_gbus0005680.028",
"subsenses": [
{
"definitions": [
"outdo someone in a competitive situation"
],
"id": "m_en_gbus0005680.029"
}
]
}
]
}
],
"language": "en",
"lexicalCategory": "Verb",
"text": "ace"
}
],
"type": "headword",
"word": "ace"
}
]
}
'String test = arr.getJSONObject (0) .toString();'은 값이 inside.it 인 것이 http://jsonviewer.stack.hu/와 같은 도구를 사용하여 json을 확장하고 분석하는 것이 좋습니다. –
링크를 제공해 주셔서 감사합니다. 훌륭한 자료입니다. –