2013-05-20 77 views
0

我在解析此JSON時遇到問題。我在JSONObject o中有以下數據。我如何獲取評論家的評分值?JSON解析 - 提取值

{ 
"total":1," 
movies": 
[{ 
     "id":"770672122", 
     "title":"Toy Story 3", 
     "year":2010, 
     "mpaa_rating":"G", 
     "runtime":103, 
     "critics_consensus":"Deftly blending comedy, adventure, and honest emotion, Toy Story 3 is a rare second sequel that really works.", 

     "release_dates":{"theater":"2010-06-18","dvd":"2010-11-02"}, 
     "ratings": 
     { 
       "critics_rating":"Certified Fresh", 
       "critics_score":99, 
       "audience_rating":"Upright", ....... 

感謝

+0

是這樣的爲jqgrid? –

回答

2

你可以做到以下幾點:

int criticsScore; 
    try { 
     criticsScore = myJsonObject.getJSONArray("movies").getJSONObject(0).getJSONObject("ratings").getInt("critics_score"); 
    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 

編輯:這是假設你JSONObject名爲myJsonObject

1

看看這篇博客我在Android平臺解析JSON文件中寫道,你會發現它很方便:

JSON Parsing

正如你所需要的方向將movies對象解析爲JSONArray,然後獲取它的第一項並提取評分JSONObject,然後提取出critics_scoreint的。

1

data_array中[ '電影'] [0] [ '收視率'] [ 'critics_score']

使用此助讀你的JSON - http://jsoneditoronline.org/

要創建我用這個對象data_array中,VAR data_array = $ .parseJSON('{「total」:1,「movies」:[{「id」:「770672122」,「title」:「玩具總動員3」,「年份」:2010,「mpaa_rating」:「G 「,」運行時間「:103,」critics_consensus「:」巧妙地融合喜劇,冒險和誠實的情感,玩具總動員3是一部非常罕見的第二部續集。「,」release_dates「:{」theater「:」2010-06 -18「,」dvd「:」2010-11-02「},」ratings「:{」critics_rating「:」Certified Fresh「,」critics_score「:99,」audience_rating「:」Upright「}}]}') ;