我是json.My中的新问题,非常简单。我在我的json文件中有一些数组,也是一个字符串类型的数据。从Json获取字符串
现在我想要获取单个文本,名称:在我的java类中从json文件中反弹。 如何从json获取此字符串? 或其他任何方式来得到这个?
JSON文件
[{
"title": "KalerKantha | OfftechIT",
"image": "",
"link": "http://www.kalerkantho.com/"
}, {
"title": "Prothom Alo | OfftechIT",
"image": "",
"link": "http://www.prothom-alo.com/"
},
...
{
"anounce": "I need this this text"
}
]
Java代码的
JsonArrayRequest movieReq = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
hidePDialog();
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
Movie movie = new Movie();
movie.setTitle(obj.getString("title"));
movie.setThumbnailUrl(obj.getString("image"));
movie.setLink(obj.getString("link").toString());
// adding movie to movies array
movieList.add(movie);
} catch (JSONException e) {
e.printStackTrace();
}
}
// notifying list adapter about data changes
// so that it renders the Grid view with updated data
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error instanceof NoConnectionError){
hidePDialog();
Toast.makeText(getActivity(), " No Internet connection! \n Please check you connection", Toast.LENGTH_LONG).show();
}};
});
它总是会在数组的最后一个对象? – Rohit5k2
不,这是一个单一的对象。 –
检查obj.has(“anounce”),然后添加其他明智的忽略,你可以为所有对象做这个 –