["[{\"timeFrom\":\"06:00:00\",\"timeTo\":\"09:00:00\",\"title\":\"First\"},{\"timeFrom\":\"09:00:00\",\"timeTo\":\"12:00:00\",\"title\":\"Second\"},{\"timeFrom\":\"12:00:00\",\"timeTo\":\"16:00:00\",\"title\":\"Third\"},{\"timeFrom\":\"16:00:00\",\"timeTo\":\"20:00:00\",\"title\":\"Fourth\"},{\"timeFrom\":\"20:00:00\",\"timeTo\":\"21:30:00\",\"title\":\"5th\"},{\"timeFrom\":\"21:30:00\",\"timeTo\":\"00:00:00\",\"title\":\"Dessert (within two hours of bedtime)th\"}]"]
我在记录 JSONArray 时得到了这个数组。我如何迭代它并获得这些值?
编辑
for (int i = 0; i < MyService.Meals.length(); ++i) {
JSONObject rec = MyService.Meals.getJSONObject(i); String text = rec.getString("timeFrom");
}
不返回任何内容,因为 MyService.Meals.length() = 1。
MyService.Meals 是 JSONArray 实例