2013-12-09 65 views
0

親愛的堆棧溢出的用戶,JSON和多個順序視圖控制器

我有以下的JSON:

{ 
"first": [ 
    { 
     "type": "headingtext", 
     "label": "Atrial Fibrillation Guideline" 
    }, 
    { 
     "type": "text", 
     "label": "Onset of Atrial Fibrillation?" 
    }, 
    { 
     "type": "button", 
     "label": "Less than 48 hours", 
     "destination": "less48hours" 
    }, 
    { 
     "type": "button", 
     "label": "More than 48 hours", 
     "destination": "more48hours" 
    } 
], 
"less48hours": [ 
    { 
     "type": "headingtext", 
     "label": "Less than 48 hours" 
    }, 
    { 
     "type": "text", 
     "label": "Patient is Stable or Unstable?" 
    }, 
    { 
     "type": "button", 
     "label": "Unstable Patient", 
     "destination": "unstableless48hours" 
    }, 
    { 
     "type": "button", 
     "label": "Stable Patient", 
     "destination": "stable" 
    } 
], 
"unstableless48hours": [ 
    { 
     "type": "headingtext", 
     "label": "Unstable Patient" 
    }, 
    { 
     "type": "button", 
     "label": "High Stroke Risk", 
     "destination": "highstrokerisk" 
    }, 
    { 
     "type": "button", 
     "label": "Low Stroke", 
     "destination": "lowstrokerisk" 
    } 
], 
"highstrokerisk": [ 
    { 
     "type": "headingtext", 
     "label": "High Stroke Risk" 
    }, 
    { 
     "type": "text", 
     "label": "Management Plan" 
    }, 
    { 
     "type": "text", 
     "label": "Cardioversion under Heparin Cover\n-Keep on monitor for 3 hours\n-Need Long Term Oral Anti-coagulation" 
    } 
], 
"lowstrokerisk": [ 
    { 
     "type": "headingtext", 
     "label": "High Stroke Risk" 
    }, 
    { 
     "type": "text", 
     "label": "Management Plan" 
    }, 
    { 
     "type": "text", 
     "label": "Cardioversion under Heparin Cover\n-Keep on monitor for 3 hours\n-No Need for Long Term Oral Anti-coagulation" 
    }  
], 
"stable": [ 
    { 
     "type": "headingtext", 
     "label": "Stable Patient" 
    }, 
    { 
     "type": "button", 
     "label": "Healthy", 
     "destination": "healthyaf" 
    }, 
    { 
     "type": "button", 
     "label": "Unhealthy", 
    "destination": "unhealthyaf" 
    } 
], 
"unhealthyaf": [ 
    { 
     "type": "headingtext", 
     "label": "AF in Stable Patients who are unhealthy" 
    }, 
    { 
     "type": "text", 
     "label": "AIM\n-Rate Control\n-Add Oral Anti-Coagulant or Aspirin if Stroke Risk is more than 2" 
    }, 
    { 
     "type": "text", 
     "label": "What is the patient's lifestyle?" 
    }, 
    { 
     "type": "button", 
     "label": "Inactive", 
     "destination": "inactive" 
    }, 
    { 
     "type": "button", 
     "label": "Active", 
     "destination": "active" 
    } 
], 
"more48hours": [ 
    { 
     "type": "headingtext", 
     "label": "More than 48 hours of onset of AF" 
    }, 
    { 
     "type": "button", 
     "label": "Stable", 
    "destination": "stable" 
    }, 
    { 
     "type": "button", 
     "label": "Unstable", 
    "destination": "unstablemore48hours" 
    }   
], 
"unstablemore48hours": [ 
    { 
     "type": "headingtext", 
     "label": "Unstable Patient" 
    }, 
    { 
     "type": "text", 
     "label": "Immediate Cardioversion with Heparin Cover\n-Oral Anticoagulant could be started afterwards and continued for 4 weeks or lifelong if stroke risk factor is more than 1" 
    }  
], 
"Inactive": [ 
    { 
     "type": "headingtext", 
     "label": "Inactive Lifestyle" 
    }, 
    { 
     "type": "text", 
     "label": "Digoxin" 
    } 
], 
"Active": [ 
    { 
     "type": "headingtext", 
     "label": "Active Lifestyle" 
    }, 
    { 
     "type": "button", 
     "label": "No Disease/Hypertension", 
    "destination": "nodiseaseht" 
    }, 
    { 
     "type": "button", 
     "label": "Congestive Heart Failure", 
    "destination": "chf" 
    }, 
    { 
     "type": "button", 
     "label": "COPD", 
     "destination": "copd" 
    } 
], 
"nodiseaseht": [ 
    { 
     "type": "headingtext", 
     "label": "Treatment Options in No Disease/HT" 
    }, 
    { 
     "type": "text", 
     "label": "Beta-Blocker \n-Diltiazem \n-Verapamil \n-Digoxin" 
    } 
], 
"chf": [ 
    { 
     "type": "headingtext", 
     "label": "Treatment Options in Congestive Heart Failure" 
    }, 
    { 
    "type": "text", 
     "label": "Beta-Blocker \n-Diltiazem" 
    } 
], 
"copd": [ 
    { 
     "type": "headingtext", 
     "label": "Treatment Options in COPD" 
    }, 
    { 
     "type": "text", 
     "label": "Diltiazem \n-Verapamil \n-Digoxin \n-Beta-1 Selective Blocker" 
    } 
] 
} 

我從StackOverflow的後續研究並沒有給我儘可能多的啓示,我想:

multiple view controllers strategy

passing controller json result to view

我的朋友設法將它翻譯成一個具有順序視圖和不同點擊的android應用程序,導致不同的視圖控制器,但怎麼可能爲iOs和Objective-C提供相同的結果?這些平臺似乎要困難得多。

我知道這樣一個事實,即JSON數據需要被解析,但不知何故在將不同JSON操作轉換爲順序視圖控制器時遇到困難。

回答

1

首先將您的響應字符串轉換爲NSData。然後

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:yourData options:kNilOptions error:&jsonError]; 
NSArray *first = [json objectForKey:@"first"]; 
for (NSDictionary *dict in first) { 
    NSString *type = [dict objectForKey:@"type"]; 
    /// and so on 
} 
+0

請試試用這個方法。 – stefbmt