我是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」),然後添加其他明智的忽略,你可以爲所有對象做這個 –