-1

Im making an application like this video: https://www.youtube.com/watch?v=mzyFQ55M7eo

but i dont want the textview display the json data, i only want its display the text "Hello (username)" mean Hello (subject_id) but i dont know how to parse json with alamofire like the video. Im researching about this but no luck. Could someone explain how to do it? Thanks in advance and sorry for my bad english.

  • There are lots of answers to this question on SO.....try to use them and if facing problem then ask here – Wings Jul 05 '18 at 09:06

1 Answers1

0

Write a function to get json data. if its Post method

let todosEndpoint: String = Your Url
            let  paramss: Parameters = ["user_id": self.userId]
            Alamofire.request(
                todosEndpoint,
                method: .post,
                parameters: paramss,
                headers: ["Content-Type": "application/x-www-form-urlencoded"])
                .responseJSON { response in
                    switch response.result {
                    case .success:
                            //if json data is a array
                            let json = JSON(response.result.value as Any)
                            if let codes = json.array {
                                for eachCode in codes {
                                    let userName = eachCode["username"].stringValue
                                     print("userName is\(userName)")

                                }
                            }

                            break

                        case .failure:
                            break
                        }
                }
iShox
  • 367
  • 2
  • 10