1

this is my code and everything is ok ,after i take the data from server ,my code doesn't work for parsing part . the strange thing is it's working with some data and not working with another and i check my data ,i have data because i change my data to string with utf8encoding ,it's perfect but my parser steel doesn't work :((

func connection(connection: NSURLConnection!, didReceiveData data: NSData!){


    var someString = NSString(data: data, encoding: NSUTF8StringEncoding)!

    var someData = someString.dataUsingEncoding(NSUTF8StringEncoding)!

    println(NSString(data:someData , encoding: NSUTF8StringEncoding)!)


    let jsonObject : AnyObject?  = NSJSONSerialization.JSONObjectWithData(data, options:   NSJSONReadingOptions.AllowFragments , error: &jsonError )

and the error is :

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Unexpected end of file while parsing object.) UserInfo=0x7fba6ad5c690 {NSDebugDescription=Unexpected end of file while parsing object.}
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0x7fba6af7b690 {NSDebugDescription=Garbage at end.}
Nurdin
  • 23,382
  • 43
  • 130
  • 308
  • Try to use alamofire-api for json parsing. http://stackoverflow.com/questions/26114831/how-to-parse-json-response-from-alamofire-api-in-swift/28622550#28622550 – Vikram Pote Mar 23 '15 at 05:08
  • i will check it ,but i think all of this kind of api use NSJsonSerialization –  Mar 23 '15 at 05:18
  • Compare http://stackoverflow.com/a/18634565/1187415. – Martin R Mar 23 '15 at 06:12
  • @MartinR wowwwwww that's work ,thank u very much my friend ,this code work perfect –  Mar 23 '15 at 08:01

0 Answers0