json日期如何存储在数组中

时间:2015-03-04 06:19:05

标签: ios swift

 data = "{\"2\":{\"Systolic_bp\":\"28\",\"Dystolic_bp\":\"29\",\"Weight\":\"22\",\"Height\":\"24\",\"Pulse\":\"26\",\"Temp\":\"25\",\"Respiration\":\"27\",\"BMI\":\"A:1:{s:4:\\\"SPO2\\\";s:1:\\\"1\\\";}\",\"BSA\":\"A:1:{s:4:\\\"SPO2\\\";s:1:\\\"1\\\";}\",\"tcomplients\":\"\",\"drdate\":\"25\\/08\\/2014\",\"medicine\":\"RABEPRAZOLE\",\"drugclass\":\"Tablet\",\"dosage\":\"1\",\"duration\":\"5 day\",\"frequency\":\"\",\"route\":\"Oral\",\"drnotes\":\"\"},\"1\":{\"tcomplients\":\"\",\"drdate\":\"25\\/08\\/2014\",\"medicine\":\"ACECLOFENAC+PARACETAMOL\",\"drugclass\":\"Tablet\",\"dosage\":\"1\",\"duration\":\"5 day\",\"frequency\":\"\",\"route\":\"Oral\",\"drnotes\":\"\"}}";   
            let jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers , error: &error) as NSDictionary


            println(jsonData)

            let dat1:NSString = jsonData.valueForKey("status")as NSString
            let dat:NSString = jsonData.valueForKey("data") as NSString
            if(dat1 == "SUCCESS")
            {
            // NSLog("Success: %d", jsonData);

                var fullName: String = dat
               // NSLog(fullName)

               //firstName = "vinod"


                let fullNameArr = fullName.componentsSeparatedByString(":")
                //NSLog(fullName)

               firstName  = fullNameArr[0]
                lastName  = fullNameArr[1]
                sex       = fullNameArr[2]
                Dob       = fullNameArr[3]
                encounter = fullNameArr[4]
                consultDR = fullNameArr[5]
               // room      = fullNameArr[6]
                //bed       = fullNameArr[7]
                //doa       = fullNameArr[8]
                //wardno    = fullNameArr[9]

                NSLog(fullNameArr[0])
                NSLog(fullNameArr[1])
                NSLog(fullNameArr[2])
                NSLog(fullNameArr[3])
                NSLog(fullNameArr[4])
                NSLog(fullNameArr[5])
               // NSLog(fullNameArr[6])
               // NSLog(fullNameArr[7])
               // NSLog(fullNameArr[8])
                //NSLog(fullNameArr[9])

尝试了这个不起作用

1 个答案:

答案 0 :(得分:0)

let jsonString = "{\"2\":{\"Systolic_bp\":\"28\",\"Dystolic_bp\":\"29\",\"Weight\":\"22\",\"Height\":\"24\",\"Pulse\":\"26\",\"Temp\":\"25\",\"Respiration\":\"27\",\"BMI\":\"A:1:{s:4:\\\"SPO2\\\";s:1:\\\"1\\\";}\",\"BSA\":\"A:1:{s:4:\\\"SPO2\\\";s:1:\\\"1\\\";}\",\"tcomplients\":\"\",\"drdate\":\"25\\/08\\/2014\",\"medicine\":\"RABEPRAZOLE\",\"drugclass\":\"Tablet\",\"dosage\":\"1\",\"duration\":\"5 day\",\"frequency\":\"\",\"route\":\"Oral\",\"drnotes\":\"\"},\"1\":{\"tcomplients\":\"\",\"drdate\":\"25\\/08\\/2014\",\"medicine\":\"ACECLOFENAC+PARACETAMOL\",\"drugclass\":\"Tablet\",\"dosage\":\"1\",\"duration\":\"5 day\",\"frequency\":\"\",\"route\":\"Oral\",\"drnotes\":\"\"}}"


if let jsonData = jsonString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) {
    var error: NSError?
    if let jsonDict = NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions.MutableContainers, error: &error) as? [String:AnyObject] {
        let dicKeys = jsonDict.keys.array
            for key in dicKeys {
                println("\n")
                if let subDic = jsonDict[key] as? [String:String] {
                    let subDicKeys = subDic.keys.array
                    for sKey in subDicKeys {
                        println(sKey + " = " + subDic[sKey]! )
                    }
                }
            }
    } else {
        println(false)
    }
} else {
    println(false)
}