作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Merriam Webster 的 API 中的文档获取单词的定义 - https://dictionaryapi.com/products/json#sec-2.def
文档显示了来自服务器的 JSON 响应的结构,我已经能够成功地将原始数据解析为一个包含“sense”对象的数组。
我的问题是能够访问“sense”JSONObject,因为我目前在一个数组中,所以我无法访问 sense 对象。我尝试在我的代码后添加 .getJSONArray(0) 和 .getJSONObject(0),但这些解决方案均无效。
如何继续将我当前拥有的这个 JSON 解析为“dt”字符串?
JSONArray merriamResults = data.getJSONArray("Merriam")
.getJSONObject(0)
.getJSONArray("def")
.getJSONObject(0)
.getJSONArray("sseq")
.getJSONArray(0)
.getJSONArray(0);
最佳答案
在这里。
String json = "{\"def\":[\n" +
" {\n" +
" \"sseq\":[\n" +
" [\n" +
" [\n" +
" \"sense\",\n" +
" {\n" +
" \"dt\":[[\"text\",\"{bc}a {a_link|backward} somersault especially\n" +
" in the air\"]]\n" +
" }\n" +
" ]\n" +
" ]\n" +
" ]\n" +
" }\n" +
"]}";
try {
JSONObject jsonObject = new JSONObject(json);
String dt = jsonObject.getJSONArray("def")
.getJSONObject(0)
.getJSONArray("sseq")
.getJSONArray(0)
.getJSONArray(0)
.getJSONObject(1)
.getJSONArray("dt")
.getJSONArray(0)
.getString(1);
Log.i("jsondata", dt);
} catch (JSONException e) {
e.printStackTrace();
}
我的日志:
12-02 21:38:12.316 14174-14174/com.example.pemba.sample I/jsondata: {bc}a {a_link|backward} somersault especially
in the air
关于java - 解析包裹在双数组中的 Merriam Webster JSON 数据属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53568248/
我正在尝试使用 Merriam Webster 的 API 中的文档获取单词的定义 - https://dictionaryapi.com/products/json#sec-2.def 文档显示了来
如何使用 python 脚本从 merriam-webster 获取特定单词的定义?我有带有文本框和按钮的窗口,我想在屏幕上打印单词的定义。谢谢 最佳答案 # Import libraries/ mo
我看到了 Merriam Webster 提供的这个很棒的 API ( http://www.dictionaryapi.com/products/api-collegiate-dictionar
我是一名优秀的程序员,十分优秀!