我有以下2个独立的JSON数组
{
"Menu": [
{
"date": "2014-11-01",
"day": "Saturday",
"food_of_the_day": "Stripped beef Spanish Style with rice",
"extra": "Sweet peas and mixed salad",
"special": "-",
"dessert": "fruit cocktail"
},
{
"date": "2014-11-30",
"day": "Sunday",
"food_of_the_day": "Pabellon criollo de Venezuela",
"extra": "salada",
"special": "-",
"dessert": "Ice cream"
}
]
}
和另一个JSON数组
{
"update_time":
[
{
"update_time_row":"2014-11-11 19:00:15"
}
]
}
要了解我的意思,请访问以下网页:http://syncandroid.comuf.com/loading_data.php
我已经可以使用标题Menu
获取json数组并在我的android应用程序中的listview中填充它,但是标题为update_time
的单独一个让我头疼。
以下是我的代码片段:
JSONArray jArray = new JSONArray("jsonResult");
for (int i=0; i < jArray.length(); i++){
JSONObject oneObject = jArray.getJSONObject(i);
// get all value here
String dateOfMainCourse=oneObject.getString("date");
String dayOfMainCourse=oneObject.getString("day");
String mainCourse=oneObject.getString("food_of_the_day");
String extraFood=oneObject.getString("extra");
// get other values from jsonobject in same way
}
JSONArray jArray2 = new JSONArray("jsonResult");
for (int i=0; i < jArray2.length(); i++){
JSONObject oneObject2 = jArray2.getJSONObject(i);
// get all value here
String update_time=oneObject.getString("update_time");
Toast.maketext(getBaseContext(),update_time,Toast.LENGTH_SHORT).show();
}
但当我为update_time
数组执行相同操作时,我得到nullpointerExeption
如何获取该单行JSON数组?