如何访问命名对象内的JSON数组? [英] How to access JSON array inside named object?
本文介绍了如何访问命名对象内的JSON数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个用于显示学校时间表的 Android 应用,JSON 数据来自 URL.但是,JSON 的格式设置为所需数组位于命名的课程"对象内.如何才能访问我需要的数组?
I'm building an Android app for displaying school timetable, with the JSON data coming from a URL. However the JSON is formatted in a way that the needed arrays are inside a named "lessons" object. How would it be possible to get access to the arrays I need?
This is how my JSON looks
{
"week": "2019-04-01",
"times": {
"1": "07:00-08:29",
"2": "08:30-10:00",
"3": "10:15-11:45",
"4": "11:55-14:00",
"5": "14:10-15:40",
"6": "15:45-17:15",
"7": "17:20-18:50",
"8": "18:55-20:25",
"9": "20:35-22:05",
"lunch": "12:40-13:15"
},
"lessons": {
"2019-04-01": [{
"lesson": "2",
"start": "08:30",
"end": "10:00",
"subject": "PHP",
"group": "IS117",
"teacher": "Jane Doe",
"room": "A-222"
}
]
},
"last update": "2019-03-28 17:02:02"
}
推荐答案
试试下面的代码,如果它对你有帮助.这将返回 2019-04-01 数组中的 jsonObject.
Try this below code if it may help you.This will return jsonObject inside 2019-04-01 array.
new JSONObject("YOUR RESPONSE STRING HERE").getJSONObject("lessons").getJSONArray("2019-04-01").getJSONObject(0)
这篇关于如何访问命名对象内的JSON数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文