2013-01-08 210 views
0

我有以下的JSON映射正確使用Restkit

{ 

    "data": { 
     "status": 200, 
     "message": "OK", 
     "text": "Succesvol ingelogd.", 
     "user": { 
      "cu_id": 1, 
      "cu_status_id": 0, 
      "cu_company_id": 1, 
      "cu_function_id": 1, 
      "cu_department_id": 1, 
      "cu_email": "[email protected]", 
      "cu_first_name": "First", 
      "cu_last_name": "Last", 
      "cu_phone_intern": "", 
      "cu_mobile_phone": "", 
      "cu_street": "", 
      "cu_number": "", 
      "cu_bus": "", 
      "cu_postalcode": "", 
      "cu_location": "", 
      "cu_country": "", 
      "cu_birthdate": "0000-00-00", 
      "cu_picture": "", 
      "cu_comment": "", 
      "cu_ison_reminder_email": 0, 
      "cu_ison_reminder_app": 0, 
      "cu_ison_reminder_web": 0, 
      "cu_first_use": 1 
     }, 
     "company": { 
      "c_id": 1, 
      "c_name": "Sanmax", 
      "c_phone": "089 68 06 39", 
      "c_fax": "089 856 929", 
      "c_website": "www.sanmax.be" 
     }, 
     "function": { 
      "cf_id": 1, 
      "cf_name": "Developer" 
     }, 
     "department": { 
      "cd_id": 1, 
      "cd_name": "Development" 
     }, 
     "statuses": [ 
      { 
       "cs_id": 3, 
       "cs_company_id": 1, 
       "cs_name": "Bezet", 
       "cs_default": 1, 
       "cs_image": "" 
      }, 
      { 
       "cs_id": 1, 
       "cs_company_id": 1, 
       "cs_name": "Online", 
       "cs_default": 0, 
       "cs_image": "" 
      }, 
      { 
       "cs_id": 2, 
       "cs_company_id": 1, 
       "cs_name": "Offline", 
       "cs_default": 0, 
       "cs_image": "" 
      }, 
      { 
       "cs_id": 4, 
       "cs_company_id": 1, 
       "cs_name": "Afwezig", 
       "cs_default": 0, 
       "cs_image": "" 
      } 
     ] 
    } 

} 

我知道我應該如何映射,如果我只得到了一個對象的JSON。在這裏我有一個數據對象。如果everthing是好的,我在數據對象中獲得了一個data.status 200,但是我也得到了一個userObject,一個companyObject,一個functionObject,一個departmentObject和一個statusObject(它也包含其他對象)。

但是,如果我沒有得到200個data.status代碼,假設我有404個data.status代碼。我只收到一個狀態碼和一條消息。

我應該如何將它映射到restkit中?

任何幫助,親切的問候

回答

0

服務器如果出現了一個錯誤不應該與一個狀態200做出迴應。因此,據我所知,這永遠不會映射到RestKit 0.20中的錯誤。

+0

首先,我感謝您的幫助。此刻,我現在對restKit有了更好的理解。我寫的代碼並不是我認爲的最好的RestKit代碼,但它是一個開始! – Steaphann