0

In my NSURLConnectionDelegate protocol function connectionDidFinishLoading(connection: NSURLConnection!), I am getting son result. But If I try to use NSURLConnection twice for connecting another API in the server, I am getting the error "The data couldn’t be read because it isn’t in the correct format". But If U run the request separately, it is giving the output.

I use the code found in stack overflow NSURLConnection Using iOS Swift

Community
  • 1
  • 1
Vinod
  • 675
  • 3
  • 7
  • 25
  • NSURLConnection is deprecated in iOS 9, better use NSURLSession. https://www.raywenderlich.com/110458/nsurlsession-tutorial-getting-started – Sandeep Kumar Jun 11 '16 at 06:21
  • The problem is not that he uses NSURLConnection, it seems that your api in server returns data which is not UTF8 encoded and NSJSONSerailization requires that the data is UTF8 encoded. – Sandeep Jun 11 '16 at 07:37
  • You can convert it to the right encoding. See http://stackoverflow.com/questions/14485868/nsjsonserialization-unable-to-convert-data-to-string – dgatwood Jun 29 '16 at 02:28

0 Answers0