Click here to Skip to main content
15,886,074 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi my friends.
i have below code for download data :
let parameters = [
            "NationalCode": "06097732",
            "password": "0012"
        ]
        let url = "http://android/home/login"
              Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding.httpBody).responseJSON { response in
            
            if let data = response.data {
                let json = String(data: data, encoding: String.Encoding.nonLossyASCII)
                print(json)
                self.lbl1.text=json
               
                }
            }

and i have true result that is:

"{\"id\":\"3\",\"name\":\"jac\"}"


naw i want separe each item of result. it mean i print "id" in one label and "name" in another label.
how can i do this???
(i am new in swift)

What I have tried:

i put this code before print(json):
if let q=json as? Dictionary<String,AnyObject>{
                   if let PName=q["name"] as? String{
                       self.lbl1.text=PName
                   }
               }
Posted
Updated 2-Sep-17 13:50pm
v4

1 solution

I am not a Swift developer so I can't debug your code for you. What I can do is offer you direction on where to find useful information that should help you with your programming (aka: problem solving).

Here is a quick Google Search: parse json in swift - Google Search[^]

Which finds a number of coding examples like:

* Working with JSON in Swift -
Apple Documentation
[^]

* Swift JSON Tutorial: Working with JSON[^]

* Parsing JSON in Swift 4 - Grok Swift[^]

* GitHub - SwiftyJSON/SwiftyJSON: The better way to deal with JSON data in Swift[^]

* Working With JSON in Swift[^]

* and much more![^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900