ios - Swift, nested dictionary with different type -


i need have data this, can return nsdictionary?, please refer code below

{     "aaa": "a1",  //value: string type     "bbb": "b1",     "ccc": "c1",     "ddd": "d1",       "dict2": {         "zzz": "z2",  //string type, nil         "ttt": "t2",         "kkk": null,         "sss": null,     } } 

code:

let dict2info = ["zzz":z1, "ttt":t1, "ccc":c1, "kkk":null, "sss":null]      var dict1 = dictionary<string, anyobject>()         dict["aaa"] = a1         dict["bbb"] = b1         dict["ccc"] = c1         dict["dict2"] = dict2info as? anyobject println("\(dict1)")  return dict1   //return parameter type "nsdictionary?"  // result:  [aaa: a1, bbb: b1, ccc: c1] 

problem:

  1. dict2 missing (i have checked key in dictionary, dict2 not exist)
  2. need return nsdictionary?

please me!

var outerdic = [string:any]() var innerdic = [string:string?]()  outerdic["aaa"] = "a1" outerdic["bbb"] = "b1" outerdic["ccc"] = "c1" outerdic["ddd"] = "d1"  innerdic["zzz"] = "z2" innerdic["ttt"] = "t2" innerdic["kkk"] = nil innerdic["sss"] = nil  outerdic["dict2"] = innerdic  println(outerdic) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -