【问题标题】:JSON and Multiple Sequential View ControllerJSON 和多顺序视图控制器
【发布时间】:2013-12-26 11:14:57
【问题描述】:

尊敬的 Stack Overflow 用户,

我有以下 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 操作转换为顺序视图控制器。

【问题讨论】:

    标签: ios json model-view-controller sequential


    【解决方案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
    }
    

    【讨论】:

    • 会用这个方法试一试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    相关资源
    最近更新 更多