2017-10-11 23 views
-2
[ 
    { 
     "updated_at":"2012-03-02 21:06:01", 
     "fetched_at":"2012-03-02 21:28:37.728840", 
     "description":null, 
     "language":null, 
     "title":"JOHN", 
     "url":"http://rus.JOHN.JOHN/rss.php", 
     "icon_url":null, 
     "logo_url":null, 
     "id":"4f4791da203d0c2d76000035", 
     "modified":"2012-03-02 23:28:58.840076" 
    }, 
    { 
     "updated_at":"2012-03-02 14:07:44", 
     "fetched_at":"2012-03-02 21:28:37.033108", 
     "description":null, 
     "language":null, 
     "title":"PETER", 
     "url":"http://PETER.PETER.lv/rss.php", 
     "icon_url":null, 
     "logo_url":null, 
     "id":"4f476f61203d0c2d89000253", 
     "modified":"2012-03-02 23:28:57.928001" 
    } 
] 
+2

你尝试过这么远吗? – BlackBeard

+0

我用http://support.oreilly.com/oreilly/topics/how_to_parse_json_in_java – Dipak

+0

提及你的问题,以及你面临的问题。 – BlackBeard

回答

0

首先为您的JSON创建一个类(Json_obj)data.Then你可以试试这个:

String json_str='[ { "updated_at":"2012-03-02 21:06:01", "fetched_at":"2012-03-02 21:28:37.728840", "description":null, "language":null, "title":"JOHN", "url":"http://rus.JOHN.JOHN/rss.php", "icon_url":null, "logo_url":null, "id":"4f4791da203d0c2d76000035", "modified":"2012-03-02 23:28:58.840076" }, { "updated_at":"2012-03-02 14:07:44", "fetched_at":"2012-03-02 21:28:37.033108", "description":null, "language":null, "title":"PETER", "url":"http://PETER.PETER.lv/rss.php", "icon_url":null, "logo_url":null, "id":"4f476f61203d0c2d89000253", "modified":"2012-03-02 23:28:57.928001" } ]'; 
Gson gson = new Gson(); 
Json_obj json_obj = gson.fromJson(json_str, Json_obj.class); 

现在你的JSON数据转换在object.You可以从该对象获取任何值。

0

我建议你只是使用jackson库来代替。

您可以只迅速拥有

ObjectMapper mapper = new ObjectMapper() // this reads json to Pojo and writes Pojo to json 

YourPojoClass obj = mapper.readValue (....) 

参考:mkyong.com/java/jackson-2-convert-java-object-to-from-json