Tag: nsjsonserialization

NSCocoaErrorDomain代码= 3840问题,同时检索到NSDictionary的NSDATA

我正在创build使用SQLite DB的iOS应用程序。 我创build了表格为: const char *sql_stmt = "CREATE TABLE IF NOT EXISTS ORDERTABLE (ID INTEGER PRIMARY KEY AUTOINCREMENT, ITEMDESC BLOB)"; 然后我必须插入self.selectedItemsDictnory字典到ItemDESC我插入为: NSData *data = [NSJSONSerialization dataWithJSONObject:self.selectedItemsDictnory options:NSJSONWritingPrettyPrinted error:nil]; NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO ORDERTABLE(ITEMDESC)VALUES( \"%@\");",data]; 取而代之,这是成功完成的。 现在我必须以相同的格式检索这本字典 我正在做的是: if (sqlite3_prepare_v2(orderDB, sqlStatement, -1, &statement, NULL) == SQLITE_OK) { while (sqlite3_step(statement) == SQLITE_ROW) { int […]

JSON写入中无效的顶级types

我试图创build一个简单的JSON对象,但我仍然得到错误,我知道我的代码中有什么问题: NSString *vCard = [BRContacts getContacts]; // this is just a string, could be nil NSDictionary *JSONdic = nil; if (vCard) { JSONdic = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"status",vCard,@"data", nil]; } else { JSONdic = [NSDictionary dictionaryWithObjectsAndKeys:@"0",@"status",@"vCard is empty",@"error", nil]; } NSError *error = nil; NSData *JSONData = [NSJSONSerialization dataWithJSONObject:JSONdic options:NSJSONWritingPrettyPrinted error:&error]; return [GCDWebServerDataResponse responseWithJSONObject:JSONdata]; 例外是 JSON写入中无效的顶级types 我也检查了JSONdic […]

AFNetworking JSON序列化问题

我发送JSON(最初存储在一个NSDictionary)使用AFNetworking。 我的对象看起来像这样(取自文档评论): /** * 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, […]

Google API关键问题

我正在开发一个应用程序,我需要从Google Places API中查询地点,并将最近的地方保存到用户的Google帐户(他们通过GIDSignINlogin到应用程序)。 Places API在控制台中被激活,并且它们的关键字是正确的,但是,URL可能有问题,并且我不断收到此错误… 可选([“error_message”:该IP,站点或移动应用程序无权使用此API密钥。从IP地址2607:f598:b349:fd01:94f8:7386:d82c:1b29收到的请求,为空引用者, “:(),”status“:REQUEST_DENIED,”html_attributions“:()]) 被调用来查询API的方法,当前经纬度来自位置pipe理器(工作正常) func saveCurrentLocation() { //API CALL let latString = String(currentLat) let longString = String(currentLong) let apiString = NSString(format: "https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=500&types=food&sensor=true&key=AIzaSyDH0jNx1WJw0pkCzbc0xaHumDoDAYYWvtk", latString, longString) let url = NSURL(string: apiString as String) let session = NSURLSession.sharedSession() let dataTask = session.dataTaskWithURL(url!) { (data, response, error) -> Void in if let urlContent = data […]

iOS NSJSON返回空值

我有以下代码 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 the data and add it to an […]

NSJSONSerialization – 如何正确地将JSON转换为NSArray?

我遇到以下问题:我想要将我的iPhone应用程序连接到服务器上的数据库。 因此我使用一些(简单的).php文件来pipe理对数据库的访问。 插入新的数据已经工作,但我有一些麻烦转换为NSMutableArray获取的数据: NSURL *contentURL = [NSURL URLWithString:[kHOSTURL stringByAppendingString:kGETBarsURL]]; NSLog(@"URL : %@", contentURL); NSData *contentData = [NSData dataWithContentsOfURL:contentURL]; NSLog(@"Data : %@", contentData); NSError *e = nil; NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData:contentData options:kNilOptions error:&e]; NSLog(@"JSON : %@", jsonArray); NSLog(@"Error : %@", e); 输出是这样的(我'XX'和缩短'数据:'): 2012-04-28 13:49:37.229 XX[14434:f803] URL : http://xx/getBars.php 2012-04-28 13:49:37.389 XX[14434:f803] Data : <5b7b2275 6e697175 […]

NSJSONSerialization不工作,NSUTF8StringEncoding正在工作

我已经阅读了文档,教程和其他堆栈问答,并挂断了我如何能够使用NSUTF8StringEncoding显示我的JSON ,但不使用NSJSONSerialization – 这是我需要将数据提取到NSDictionary或NSArray 。 我相信这是从我的url返回的NSData格式的问题? 编辑这是错误:错误域= NSCocoaErrorDomain代码= 3840“操作无法完成。(cocoa错误3840.)”(垃圾在结束。)UserInfo = 0x8aabc30 NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.sampleURL.com"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15.0]; NSMutableData* responseData = [NSMutableData dataWithCapacity: 0]; – (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { //this works, and have NSLog below responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"string %@", responseString); [responseData appendData:data]; responseData = [[NSMutableData alloc] initWithData:data]; //this is null in […]

NSJSONSerialization unboxes NSNumber?

我正在使用NSJSONSerialization将JSON文档转换为Core Foundationtypes。 我有一个字段在我的JSON这是一个“数字”。 有时是整数,有时候是浮点数。 现在,问题是当NSJSONSerialization把我的JSON变成一个NSDictionary ,我试图提取使用objectForKey的数字,有时它是一个int,有时它是一个双。 看来NSJSONSerialization并不是简单的把它放在一个NSNumber包装器中,而是实际上将这个值解开,并把它插入到NSDictionary 。 很奇怪。 我以为你应该把原语放进一个NSDictionary 。 所以我现在的问题是,我不知道什么types(INT或双)我应该铸造来保存实际的数值。 任何人都知道一个出路?

创build一个与NSJSONSerialization dataWithJSONObject一起使用的对象:options:error:

目前为了使用这个function,我把我的对象“转换”成一个字典。 即属性名称成为键,属性值成为值。 有没有办法正确做到这一点,使一个对象将与此function? 即类似于encodeWithCoder和initWithCoder用于NSUserDefaults 。 我想做… NSData *data = [NSJSONSerialization dataWithJSONObject:myObject options:0 error:nil]; 此刻我做了一些像… NSData *data = [NSJSONSerialization dataWithJSONObject:[myObject dictionaryRepresentation] options:0 error:nil];

字符0,NSJSONSerialization周围的值无效

我从我的服务器得到一个有效的回应: – (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { // Append the new data to the instance variable you declared //[_responseData appendData:data]; NSString *responseBody = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"%@",responseBody); if(data != NULL) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { NSError *error = nil; //NSMutableArray *jsonArray = [[CJSONDeserializer deserializer] deserializeAsArray:[responseBody dataUsingEncoding:NSUTF8StringEncoding] error:&error]; NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments […]