2013-12-09 3 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 앱으로 변환 할 수 있었지만 어떻게 iO와 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