nsjsonserialization

FHSTwitterEngine - 'NSInvalidArgumentException','data parameter is nil'

一笑奈何 提交于 2019-12-10 10:24:33
问题 I'm using FHSTwitterEngine to post a gif to twitpic. When I have a wifi or 3G connection on the iphone everything works fine. But I also want to implement some error handling for when there is no connection or when the upload failed. So for testing I put the iphone in airplane mode and try to upload to twitpic using the following method: id returned = [[FHSTwitterEngine sharedEngine] uploadImageToTwitPic:gif withMessage:@"message" twitPicAPIKey:@"key"]; but when I do that I immediately get

Parsing JSON with NSJSONSerialization: Error 3840 - Data Corrupted?

≡放荡痞女 提交于 2019-12-10 09:46:40
问题 I've read many Q/As on this problem but couldn't find an answer that fits my situation. I retrieve a JSON response from a REST service I've created in PHP. This is my code: NSURLResponse *response = nil; NSError *theError1 = nil; NSError *theError2 = nil; NSURL *webServiceUrl = [NSURL URLWithString:@"http://..."]; NSURLRequest *request = [NSURLRequest requestWithURL:webServiceUrl cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30]; NSData *theData = [NSURLConnection

NSJSONSerialization parsing response data

寵の児 提交于 2019-12-09 23:48:34
问题 I created a WCF service, which provides the following response to my POST operation: "[{\"Id\":1,\"Name\":\"Michael\"},{\"Id\":2,\"Name\":\"John\"}]" My call to JSONObjectWithData, doesn't return any error, yet I can't enumerate over the results, what am I doing wrong? NSError *jsonParsingError = nil; NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments error:&jsonParsingError]; NSLog(@"jsonList: %@",

iOS Send JSON data in POST request using NSJSONSerialization

安稳与你 提交于 2019-12-09 20:48:37
问题 I know that there are similar questions posted as I have read though most all of them and still am having problems. I am trying to send JSON data to my server, but I do not think the JSON data is being received. I'm just not sure what I am missing. Below is my code... Method to send data to server. - (void)saveTrackToCloud { NSData *jsonData = [self.track jsonTrackDataForUploadingToCloud]; // Method shown below. NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding

Valid JSON, but 'Cocoa error 3840' from AFNetworking/NSJSONSerialization

删除回忆录丶 提交于 2019-12-09 18:08:13
问题 I've been hacking away for hours trying to solve this problem to no avail - it seems like my only option is to post here to see if anyone can shed some light on this issue. It may be an issue with AFNetworking, or (more likely), it may be an issue with my code. The code I am using works perfectly for 99% of the operations within my application. I am developing an app that leverages Elastic Search by building JSON searches, sending them off and receiving a response from the server. Here is an

iOS JSON Parse not working (returns null dictionary)

只愿长相守 提交于 2019-12-09 15:44:45
问题 I use the NSJSONSerialization 's JSONObjectWithData:data options: error: to parse JSON data returned from a server. Now for the options parameter I use: NSJSONReadingAllowFragments . You can look below and see the actual JSON (where I believe the problem is). The error message I get is: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x6895da0 {NSDebugDescription=Invalid value around character 0.

How to convert NSDictionary to custom object

僤鯓⒐⒋嵵緔 提交于 2019-12-09 14:54:46
问题 I have a json object: @interface Order : NSObject @property (nonatomic, retain) NSString *OrderId; @property (nonatomic, retain) NSString *Title; @property (nonatomic, retain) NSString *Weight; - (NSMutableDictionary *)toNSDictionary; ... - (NSMutableDictionary *)toNSDictionary { NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; [dictionary setValue:self.OrderId forKey:@"OrderId"]; [dictionary setValue:self.Title forKey:@"Title"]; [dictionary setValue:self.Weight forKey:@

Mapping JSON objects in custom objects

风格不统一 提交于 2019-12-09 13:39:49
问题 I've been searching if it is possible to get a JSON dictionary or array and directly map it in a custom object whose properties have the same name as the JSON tags, but I din't find any information regarding that. I've been parsing JSON dictionaries manually, like this: id deserializedObj = nil; id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&error]; if ([jsonObject isKindOfClass:[NSDictionary class]]) { NSDictionary *jsonDictionary

Convert JSON to NSArray

ⅰ亾dé卋堺 提交于 2019-12-09 06:07:40
问题 I have a JSON array being output on a page. I would like to convert this JSON array into an NSArray. This is the JSON output on the web page: [{"city":"Current Location"},{"city":"Anaheim, CA"},{"city":"Los Angeles, CA"},{"city":"San Diego, CA"},{"city":"San Francisco, CA"},{"city":"Indianapolis, IN"}] This is my NSURL call and NSJSONSerialization: NSString *cityArrayURL = [NSString stringWithFormat:@"http://site/page.php"; NSData *cityData = [NSData dataWithContentsOfURL:[NSURL URLWithString

How do I access JSON data in an NSMutableArray?

前提是你 提交于 2019-12-08 15:19:09
问题 I'm trying to access JSON data that I have taken from a website and stored in an array. First, however, I want to filter out everything but the "title" information, which I am doing using the valueForKey: method. In order to test this I am writing them to the log using the NSLog method, however when I run this I get "null". Can anyone advise me, as to why I'm getting what I'm getting? Thanks for your help, much appreciated. { NSURL *redditURL = [NSURL URLWithString:@"http://pastebin.com/raw