Pregunta

Dear Stack Overflow Users,

I have the following 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"
    }
]
}

My following research from StackOverflow didn't give me as much enlightenment as I wished:

multiple view controllers strategy

passing controller json result to view

My friend managed to translate this into an android app with sequential views and different taps leading to different view controllers, but how could it be possible to come up with the same result for iOs and Objective-C? It seems to be much more difficult for these platforms.

I am aware of the fact that the JSON Data needs to be parsed but somehow finding difficulty in translating the different JSON actions into sequential view controllers.

¿Fue útil?

Solución

first transform your response string to NSData. Then

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
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top