nsjsonserialization

Could not cast value of type 'NSTaggedPointerString' to 'NSNumber'

ぃ、小莉子 提交于 2019-12-18 10:58:27
问题 I have a Swift struct like this. struct Usage { var totalData: Double var remainingTotalData: Double init(jsonData: NSData) { var jsonDict = [String: AnyObject]() do { jsonDict = try NSJSONSerialization.JSONObjectWithData(jsonData, options: []) as! [String: AnyObject] } catch { print("Error occurred parsing data: \(error)") } totalData = jsonDict["totalfup"] as! Double remainingTotalData = jsonDict["totalrem"] as! Double } } From an API, I get the following JSON response. This is the println

NSJSONSerialization not working as expected in a Playground

戏子无情 提交于 2019-12-18 09:12:14
问题 I have to get football game schedule via JSON and extract date of each game of one of the specific universities. I tried: let url = NSURL(string: "SCHOOL URL") let request = NSURLRequest(URL: url!) let session = NSURLSession.sharedSession() let task = session.dataTaskWithRequest(request){ (data, response, error) -> Void in do{ let jsonData = try NSJSONSerialization.JSONObjectWithData(data!, options: .AllowFragments) if let schedule = jsonData["schedule"] as? [[String: AnyObject]]{ for game in

NSJSONSerialization and Emoji

心已入冬 提交于 2019-12-18 06:58:30
问题 I'm currently trying to POST some JSON containing emojis to a python API. I tried feeding the NSJSONSerialization directly with the string containing the emojis from my UITextField but the serializer crashed with no meaningful explanation. Afterwards I tried to do some format conversion and ended up with something like this: NSString *uniText = mytextField.text; NSData *msgData = [uniText dataUsingEncoding:NSNonLossyASCIIStringEncoding]; NSString *goodMsg = [[NSString alloc] initWithData

Reading in a JSON File Using Swift

无人久伴 提交于 2019-12-17 02:52:27
问题 I'm really struggling with trying to read a JSON file into Swift so I can play around with it. I've spent the best part of 2 days re-searching and trying different methods but no luck as of yet so I have signed up to StackOverFlow to see if anyone can point me in the right direction..... My JSON file is called test.json and contains the following: { "person":[ { "name": "Bob", "age": "16", "employed": "No" }, { "name": "Vinny", "age": "56", "employed": "Yes" } ] } The file is stored in the

JSONObjectWithData returns null if degree symbol is in json object

♀尐吖头ヾ 提交于 2019-12-14 03:57:34
问题 JSONObjectWithData is returning null without an error if the json string contains a degree sign ° (U+00B0). The json string displays fine if I serve it to my desktop browser. My code (a category) with a few NSLogs to see what is happening looks like this... +(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString *)urlAddress{ __autoreleasing NSError* error = nil; NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlAddress] options:NSDataReadingUncached error:&error];

Urban Airship crashes when calling takeoff

╄→гoц情女王★ 提交于 2019-12-14 03:45:09
问题 Upgrading to UrbanAirship 3.0.0 with Xcode 5.0, I'm getting an error when calling this code: [UAirship takeOff:config]; The error is +[NSJSONSerialization stringWithObject:]: unrecognized selector sent to class 0x3b2ca9fc 2013-09-19 15:02:31.981 [178:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSJSONSerialization stringWithObject:]: unrecognized selector sent to class 0x3b2ca9fc' This doesn't seem to appear when setting the key "inProduction" to

AFNetworking JSON serialization problems

陌路散爱 提交于 2019-12-13 03:57:36
问题 I'm sending JSON (initially stored in an NSDictionary) using AFNetworking. My object looks like this (taken from a doc comment): /** * Sends a create request to the API server * Success will be a dictionary containing: * * playlistSession: { * "mediaSegments": {}, * "mediaSequence": 0, * "timeElapsed": 0, * "config": { * "maxSegments": 4, * "targetDuration": 10 * }, * "meta": { * "id": "test", * "shouldBeAvailable": false, * "isAvailable": false, * "shouldFinish": false, * "isFinished": false

AFNetworking base64 parameter, characters being escaped by NSJSONSerialization

℡╲_俬逩灬. 提交于 2019-12-12 21:22:51
问题 I am attempting to submit an image to CardShark's API using AFNetworking. NSData *imageData = UIImageJPEGRepresentation(cardImage, 1.0); NSDictionary *parameters = @{@"front" : [imageData base64EncodedStringWithSeparateLines:NO]}; NSString *path = [NSString stringWithFormat:@"cardShark?webhookUrl=%@&apiKey=%@", kCardSharkWebHookURLEncodedString, kCardSharkAPIKey]; [self postPath:path parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { completion

iOS NSJSON Returning Null

☆樱花仙子☆ 提交于 2019-12-12 05:02:48
问题 I have the following code hostStr = [hostStr stringByAppendingString:post]; NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]]; NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding]; NSError *error = nil; NSDictionary *result = [NSJSONSerialization JSONObjectWithData:dataURL options:kNilOptions error:&error]; NSArray *files = [result objectForKey:@"GV_Return"]; NSLog(@"Files: %@", files); // For Each Key we seperate

How to include null value in the JSON via NSJSONSerialization?

旧城冷巷雨未停 提交于 2019-12-12 04:43:05
问题 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":