nsjsonserialization

The Operation couldn't be completed. (Cocoa error: 3840.)

99封情书 提交于 2019-12-01 15:08:05
问题 I am trying to parse JSON for an ios 6 app, but can't seem to get it to work. I have scoured tons of forums but haven't found a solution that works, that I understand enough to implement, or that applies. I apologize if there is one that I missed. First I have a test WebService that as far as I can tell returns valid JSON http://thetrouthunter.com/SVLocationsAPI.php Second, here is my Objective-C code: + (NSDictionary *)connectToService:(NSString *)query { NSError *error = nil; query =

Swift iOS API controller stopped working

▼魔方 西西 提交于 2019-12-01 12:19:24
I am using a file to handle my calls to my APIs which looks like this: import UIKit protocol APIControllerProtocol { func JSONAPIResults(results: NSArray) } class APIController: NSObject { var delegate:APIControllerProtocol? func GetAPIResultsAsync(urlString:String, elementName:String) { //The Url that will be called var url = NSURL.URLWithString(urlString) //Create a request var request: NSURLRequest = NSURLRequest(URL: url) //Create a queue to hold the call var queue: NSOperationQueue = NSOperationQueue() // Sending Asynchronous request using NSURLConnection NSURLConnection

Swift iOS API controller stopped working

三世轮回 提交于 2019-12-01 07:54:17
问题 I am using a file to handle my calls to my APIs which looks like this: import UIKit protocol APIControllerProtocol { func JSONAPIResults(results: NSArray) } class APIController: NSObject { var delegate:APIControllerProtocol? func GetAPIResultsAsync(urlString:String, elementName:String) { //The Url that will be called var url = NSURL.URLWithString(urlString) //Create a request var request: NSURLRequest = NSURLRequest(URL: url) //Create a queue to hold the call var queue: NSOperationQueue =

NSJSONSerialization bug?

半腔热情 提交于 2019-12-01 02:56:47
Been trying to debug a crash for the past 10 hours and finally, I simplified it to this code: NSError *error = nil; NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"payload" ofType:@"txt"]]; id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; With NSZombieEnabled, this crashes the app at the third line (where the parsing happens) and it logs: *** -[CFString retain]: message sent to deallocated instance 0x758afa0 The contents of payload.txt are: [ { "created_at":"2013-02-15T23:46:02-05:00",

Use NSSerialization.datawithJSON in Swift 2

半城伤御伤魂 提交于 2019-11-30 20:48:59
Been trying to get this to work in Swift 2.0, the error says: Type NSJSONWritingOptions cannot conform to protocol NilLiteralConvertible at var options = prettyPrinted... : func JSONStringify(value: AnyObject,prettyPrinted:Bool = false) -> String { var options = prettyPrinted ? NSJSONWritingOptions.PrettyPrinted : nil if NSJSONSerialization.isValidJSONObject(value) { do{ let data = try NSJSONSerialization.dataWithJSONObject(value, options: options) if let string = NSString(data: data, encoding: NSUTF8StringEncoding) { return string as String } } catch { } } return "" } Jackspicer let options =

how to create json in objective-c

房东的猫 提交于 2019-11-30 08:20:07
NSData* jsonDataToSendTheServer; NSDictionary *setUser = [NSDictionary dictionaryWithObjectsAndKeys:[@"u" stringByAppendingString:my.id],@"id", @"GET_USER_INFO",@"command", @"",@"value", nil]; NSLog(@"%@", jsonDataToSendTheServer); Here is my code. When I run above code I get this print <7b226964 223a2275 35383738 37373334 31222c22 636f6d6d 616e6422 3a224745 545f5553 45525f49 4e464f22 2c227661 6c756522 3a22227d> I don't have any idea whether I can created a json or not. How can I fix this? bryanmac You're missing this line to convert it to json NSData* jsonData = [NSJSONSerialization

How to include null value in the JSON via NSJSONSerialization?

半世苍凉 提交于 2019-11-30 08:01:24
I think I get it how to use the NSJSONSerialization over all. The call I am making is: [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error] where parameters is a NSDictionary which includes keys and values to use in the JSON request. Everything is fine and all, until I have to use null as a value instead of an empty string. I can't find a way to set the value as null at all. The example of json that I need to create is: {"target" {"firstname":<firstname>, "lastname":<lastname>}, "error":null } The way server is setup is that it's expecting either an error as a string or a

HTTP POST error Handling in Swift 2

允我心安 提交于 2019-11-30 06:42:10
I'm new here, and this is my first question... I try to write an App in Swift 2 that makes an HTTP POST request but I can't figure out how to use the new error handling of Swift 2. Can anyone tell me please how to implement the " do-try-catch " error handling of Swift 2 to the code snippet below? (This code snippet uses the old error handling of swift 1.2) func post(params : Dictionary<String, String>, url : String) { var request = NSMutableURLRequest(URL: NSURL(string: url)!) var session = NSURLSession.sharedSession() request.HTTPMethod = "POST" var err: NSError? request.HTTPBody =

Use NSSerialization.datawithJSON in Swift 2

一个人想着一个人 提交于 2019-11-30 05:23:57
问题 Been trying to get this to work in Swift 2.0, the error says: Type NSJSONWritingOptions cannot conform to protocol NilLiteralConvertible at var options = prettyPrinted... : func JSONStringify(value: AnyObject,prettyPrinted:Bool = false) -> String { var options = prettyPrinted ? NSJSONWritingOptions.PrettyPrinted : nil if NSJSONSerialization.isValidJSONObject(value) { do{ let data = try NSJSONSerialization.dataWithJSONObject(value, options: options) if let string = NSString(data: data,

NSJSONSerialization bug?

橙三吉。 提交于 2019-11-30 01:24:24
问题 Been trying to debug a crash for the past 10 hours and finally, I simplified it to this code: NSError *error = nil; NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"payload" ofType:@"txt"]]; id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; With NSZombieEnabled, this crashes the app at the third line (where the parsing happens) and it logs: *** -[CFString retain]: message sent to deallocated