如何从下面提到的json中检索标题字段:

时间:2015-11-02 07:54:57

标签: java json

enter image description here如何从下面提到的JSON中检索标题字段:

{"feed":[{"image":"http:\/\/xyz\/xyz\/600x519\/web2images\/www.xyz.com\/2015\/09\/16\/xyz.jpg","story_id":"83","slug_intro":"xyz","title":"xyz","videoflag":0,"version":"2","channel_slno":"123","pubdate":"2015-09-17 00:08:00"}],"bigimage":0}

请在JAVA中提供代码。

请说明为什么我收到此错误,如上图所示

1 个答案:

答案 0 :(得分:2)

String myJSONString = "{\"feed\":[{\"image\":\"http://xyz/xyz/600x519/web2images/www.xyz.com/2015/09/16/xyz.jpg\",\"story_id\":\"83\",\"slug_intro\":\"xyz\",\"title\":\"xyz\",\"videoflag\":0,\"version\":\"2\",\"channel_slno\":\"123\",\"pubdate\":\"2015-09-17 00:08:00\"}],\"bigimage\":0}";
JSONObject json = new JSONObject(myJSONString);
JSONArray dataJsonArray = json.getJSONArray("feed");

for(int i=0; i<dataJsonArray.length; i++) {
 JSONObject dataObj = dataJsonArray.get(i);
 String title = dataObj.getString("title");
 //Similarly you can extract for other fields.
}

输出:Title:xyz