swift - Perfect JSON structure -


i've been looking around , learning json little bit. thought start learning easy seems not. trying json database. example has brand names , every brand has own products info. i've done longer:

{   "snuses": {     "brands": {       "catch": [         {           "products": "catch eucalyptus white large",           "nicotine": "8.0"         }       ] } 

now using firebase parse "brands" "catch" etc.. can't.

in swift trying this:

override func viewdidload() {     super.viewdidload()     ref = firdatabase.database().reference()     ref.observesingleeventoftype(.value, withblock: { snapshot in          self.ref = firdatabase.database().reference().child("snuses").child("brands")          self.ref.observeeventtype(.value, withblock: { snapshot -> void in             brands in snapshot.children {                 print(brands)             }         })      }) } 

how reference brands first? , how store list of brands separately?

some smart guys told me not correct don't know wrong json structure. how can flatten it?

i red docs says how best little complicaetd. can point me right direction?

you need allkeys allkeys snap

   let ref = firdatabase.database().reference().child("snuses").child("brands")      ref.observesingleeventoftype(.value, withblock: { (snapshot) in         if snapshot.exists() {             if let allproducts = (snapshot.value?.allkeys)! as? [string]{                 self.snusbrandsarray = allproducts                                       self.productstable.reloaddata()             }         }     }) 

Comments