Sunday 20 May 2018

Reading data from Local Json file using Alamofire in swift3


//Reading data from Local Json file instead of Service urls using Alamofire in swift3


func getwordmeaningdata()
  {
   
    if let path = Bundle.main.path(forResource: "localfile", ofType: "json") {
       let url=URL(fileURLWithPath: path)
        Alamofire.request(url).responseJSON { response in
            
            if let JSON = response.result.value {
                print("JSON: \(JSON)") 
            }
        }
}


//This is the data of local json file not getting from URL
localfile.json


{
  "person":[
    {
      "name": "Bob"
     
    },
    {
      "name": "Vinny"
      }

]
}

1 comment:

  1. its fine, but status code is always nil.. Do you know the reason?

    ReplyDelete

Remove bottom line in navigation bar

navigationController ?. navigationBar . setBackgroundImage ( UIImage (), for: . any , barMetrics: . default )          navigat...