我正在尝试从牛津词典解析数据。但是,我得到的价值找不到错误。
{
"id": "ace",
"metadata": {
"operation": "retrieve",
"provider": "Oxford University Press",
"schema": "RetrieveEntry"
},
"results": [
{
"id": "ace",
"language": "en-gb",
"lexicalEntries": [
{
"entries": [
{
"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"
],
"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-gb",
"lexicalCategory": {
"id": "noun",
"text": "Noun"
},
"text": "ace"
},
{
"entries": [
{
"homographNumber": "101",
"senses": [
{
"definitions": [
"very good"
],
"id": "m_en_gbus0005680.016"
}
]
}
],
"language": "en-gb",
"lexicalCategory": {
"id": "adjective",
"text": "Adjective"
},
"text": "ace"
},
{
"entries": [
{
"homographNumber": "102",
"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-gb",
"lexicalCategory": {
"id": "verb",
"text": "Verb"
},
"text": "ace"
}
],
"type": "headword",
"word": "ace"
},
{
"id": "ace",
"language": "en-gb",
"lexicalEntries": [
{
"entries": [
{
"homographNumber": "200",
"senses": [
{
"definitions": [
"a person who has no sexual feelings or desires"
],
"id": "m_en_gbus1190638.004"
}
]
}
],
"language": "en-gb",
"lexicalCategory": {
"id": "noun",
"text": "Noun"
},
"text": "ace"
},
{
"entries": [
{
"homographNumber": "201",
"senses": [
{
"definitions": [
"(of a person) having no sexual feelings or desires; asexual"
],
"id": "m_en_gbus1190638.006"
}
]
}
],
"language": "en-gb",
"lexicalCategory": {
"id": "adjective",
"text": "Adjective"
},
"text": "ace"
}
],
"type": "headword",
"word": "ace"
}
],
"word": "ace"
}
这是我用来解析数据的Java代码。该代码尚未完成。但是,我只是想测试开始的解码阶段。
//data is string
OfflineWordItems o = new OfflineWordItems();
try{
JSONObject o0 = new JSONObject(data);
JSONArray a1 = o0.getJSONArray("results");
for (int i = 0; i<a1.length(); i++){
JSONObject o2 = a1.getJSONObject(i);
JSONArray a2 = o2.getJSONArray("lexicalEntries");
for(int i2 = 0; i2<a2.length(); i2++){
JSONObject o3 = a2.getJSONObject(i2);
JSONArray a3 = o3.getJSONArray("entries");
for(int i3 = 0; i3<a3.length(); i3++){
JSONObject o4 = a3.getJSONObject(i3);
JSONArray a4 = o4.getJSONArray("senses");
for(int i4=0; i4<a4.length(); i4++){
JSONObject o5 = a4.getJSONObject(i4);
o.definition = o5.getString("definitions");
}
}
JSONObject o6 = o3.getJSONObject("lexicalCategory");
o.lexicalCategoryId = o6.getString("id");
o.lexicalCategoryText = o6.getString("text");
}
}
return o;
} catch (Exception e){
e.printStackTrace();
return null;
}
这是我得到的错误。我尝试了其他解码模式。然后显示不匹配类型错误。
W/System.err: org.json.JSONException: No value for results
W/System.err: at org.json.JSONObject.get(JSONObject.java:392)
W/System.err: at org.json.JSONObject.getJSONArray(JSONObject.java:587)
编辑:即使我只写这些行:
JSONObject o0 = new JSONObject(data);
JSONArray a1 = o0.getJSONArray("results");
我仍然遇到相同的错误。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。