2017-10-17 197 views
-2
"sport_events": [ 
    { 
     "id": "sr:match:12606716", 
     "scheduled": "2017-09-27T10:00:00+00:00", 
     "start_time_tbd": false, 
     "status": "closed", 
     "tournament_round": { 
      "type": "group", 
      "number": 1, 
      "group": "Gr. 4" 
     }, 
     "season": { 
      "id": "sr:season:45960", 
      "name": "U17 European Ch.ship QF 17/18", 
      "start_date": "2017-09-27", 
      "end_date": "2018-04-30", 
      "year": "17/18", 
      "tournament_id": "sr:tournament:755" 
     }, 
     "tournament": { 
      "id": "sr:tournament:755", 
      "name": "U17 European Ch.ship QF", 
      "sport": { 
       "id": "sr:sport:1", 
       "name": "Soccer" 
      }, 
      "category": { 
       "id": "sr:category:392", 
       "name": "International Youth" 
      } 
     }, 
     "competitors": [ 
      { 
       "id": "sr:competitor:22646", 
       "name": "Russia", 
       "country": "Russia", 
       "country_code": "RUS", 
       "abbreviation": "RUS", 
       "qualifier": "home" 
      }, 
      { 
       "id": "sr:competitor:22601", 
       "name": "Faroe Islands", 
       "country": "Faroe Islands", 
       "country_code": "FRO", 
       "abbreviation": "FRO", 
       "qualifier": "away" 
      } 
     ] 
    }, 
+3

你有沒有試過Google的東西,比如「在Android中解析JSON?」 – Derlin

+0

之前解析過json嗎?使用正確的成員創建您的pojo模型和android **您可以使用gson庫**而不是舊的javax.rs – LenglBoy

+0

@LenglBoy它是我的第一次 –

回答

0

加入到這個您build-script.gradle添加GSON到您的項目:

dependencies { 
    compile 'com.google.code.gson:gson:2.8.2' 
} 

現在創建你所需要的類,但首先糾正你的JSON字符串。我想你在開始的時候忘了一個屬性名稱。這是你最好的朋友:json formatter online

你糾正了json-string和......你創建了WrapperPojo模型類與所需的屬性,您解析字符串回wrapper-objectgetter/setter你更改後/獲取數據超出了它。

Gson gson = new GsonBuilder().create(); 
Wrapper wrap = gson.fromJson(jsonString, Wrapper.class); 

不要忘記try-catch塊,因爲可能會有很多拋出的異常。 祝你好運。

How-to-for-beginner