Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am having the Json data as shown below in this I need to get the data that which key value pair for default is 1 then i need to get the remaining dictionaries data and need to be passed to the user to display can any one tell me how to implement this ?

And my code is as shown below

            if let addressArray = jsonObj!.value(forKey: "address") as? NSArray{
                    for array in addressArray {
                        if let addressDict = array as? NSDictionary{
                            if let Default = addressDict.value(forKey: "default"){

                            }
                        }
                    }
                }
 "address": [
    {
      "default": 0, 
      "number": 9123456711, 
      "name": "Ramesh", 
      "address": "No:11/111 ,cross street,Nungambakkam,mylapore,chennai :600088"
    }, 
    {
      "default": 1, 
      "number": 8123456722, 
      "name": "Vignesh", 
      "address": "No:22/222 ,cross street,Perambur,chennai :600012"
    }, 
    {
      "default": 0, 
      "number": 7123456733, 
      "name": "Rajesh", 
      "address": "No:33/333 ,cross street,Villivakkam,chennai :600045"
    }
  ]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
213 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can check if Default equals 1 and add those values to an array.

var defaultArray = [NSDictionary]()
if let addressArray = jsonObj!.value(forKey: "address") as? NSArray{
                    for array in addressArray {
                        if let addressDict = array as? NSDictionary{
                            if let Default = addressDict.value(forKey: "default"){
                               if Default == 1 {
                               defaultArray.append(addressDict)
                              }
                            }
                        }
                    }
                }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...