我试图从JSONArray
内部数组中获取值,我能够成功检索整个JSON值到JSONArray
但无法检索JSONArray
中的值。当我将JSONArray
转换为JSONObject
以获取存储在JSONArray
中的值。它提供了错误:org.json.JSONException: No value for "banner"
Json数组内部检索值Android
这里是JSON代码,我验证JSON代码jsonlint.com而事实证明,JSON是验证,
[
\t {"code":"banner","moduletitle":0,
\t "banner":
\t \t [
\t \t \t {"image":"http://imageurl"},
\t \t \t {"image":"http://imageurl"},
\t \t \t {"image":"http://imageurl"}
\t \t ]
\t \t
\t }
]
余米试图在3小时也没有运气得到这个。我新的JSON,不知道JSON如何实际工作,也读取邻接GSON Library获得JSON值。这里是我的Java代码。
JSONArray jsonObj = null;
String image_url = "";
String banner_code ="";
try {
jsonObj =new JSONArray(lib_function.getJSONUrl(jsontags.Top_Banner_JOSN_URLs));
Log.d("value retrun :","" +jsonObj);
//---vlaue is coming and print in Log ----//
} catch (JSONException e) {
Log.v("Error in Parser :", " " + e);
Log.d("no value retrun :", "failed to convert");
}
try{
JSONObject jo = new JSONObject();
JSONArray ja = new JSONArray();
// populate the array
jo.put("arrayName", jsonObj);
JSONArray subArray = jo.getJSONArray("banner");
image_url= subArray.getString(Integer.parseInt("image"));
Log.d("banner code",""+subArray);
}catch(Exception e)
{
Log.d("not working",""+e);
}
我folllow这个问题,但运气: How to parse JSON Array inside another JSON Array in Android
如果有人建议,我在做错误的将是升值。或让我知道,在哪里我可以得到更多关于JSON的信息
UPDATE谢谢大家给他们宝贵的时间来回答我的愚蠢问题。所有答案都是正确的,但我只能接受一个答案。非常感谢所有
我的JSONArray创建另一个JSONObject的价值和通过指定键获取值。 –