提取存储在字典中的JSON数据

时间:2017-02-03 07:06:12

标签: json swift xcode

["Subscriptions": {
StudentData = "<null>";
SubscriptionsData =     (
            {
        AcademicYear = "2015-2016";
        DataBasePath = "abc";
        Institute = xyz;
        IsCentral = 1;
        IsExists = 0;
        SubscriptionId = 1059;
    }
);
UsrData =     {
    "EmpNum_AdminNum" = C001;
    Id = 1;
    Name = "Vamshi ";
    RoleName = "p_staff_superadmin";
};
}]

我是swift的新手,无法提取像“dataBasePath”

这样的特定参数

2 个答案:

答案 0 :(得分:0)

您可以使用此

在字符串中获取数据库路径
if let subscriptionsData = result["SubscriptionsData"].arrayObject as Array<AnyObject>!
                    {
                        if let item = subscriptionsData[0] as? [String: AnyObject]
                        {
                            if let dataBasePath = item["DataBasePath"] as? String
                            {
                                print(dataBasePath)
                            }
                        }
                    }

答案 1 :(得分:-1)

if let subscriptionsData = Subscriptions.objectForKey("SubscriptionsData") as NSArray {

     if let subscriptionsDataDictionary = subscriptionsData.objectAtIndex(0) as NSDictionary {
             let DataBasePath = subscriptionsDataDictionary.objectForKey("DataBasePath") as? String
            }
     }