Tag: json

将parameter passing给Objective C中的JSON Web服务

我试图调用一个web服务方法,并传递给它一个参数。 这是我的web服务方法: [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public void GetHelloWorld() { Context.Response.Write("HelloWorld"); Context.Response.End(); } [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public void GetHelloWorldWithParam(string param) { Context.Response.Write("HelloWorld" + param); Context.Response.End(); } 这是我的目标C代码: NSString *urlString = @"http://localhost:8080/MyWebservice.asmx/GetHelloWorld"; NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod: @"POST"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; NSError *errorReturned = nil; […]

如何使用swift语言创build和发送json数据到服务器

我是IOS开发新手,我已经开始使用迅速的语言。 我试图从两个文本字段中获取值,并将这两个文本字段转换为json,然后将该json发送到服务器receive.php。 让那个拖拽文本字段为 – 名称的concider通过 如何创build一个Json&发送到服务器,当一个button被点击?

Cocoa-Touch – 如何parsing本地Json文件

我在iOS开发新手,我试图parsing一个本地的Json文件,如 {"quizz":[{"id":"1","Q1":"When Mickey was born","R1":"1920","R2":"1965","R3":"1923","R4","1234","response","1920"},{"id":"1","Q1":"When start the cold war","R1":"1920","R2":"1965","R3":"1923","rep4","1234","reponse","1920"}]} 这里是我的代码: NSString *filePath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"json"]; NSString *myJSON = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL]; // Parse the string into JSON NSDictionary *json = [myJSON JSONValue]; // Get all object NSArray *items = [json valueForKeyPath:@"quizz"]; NSEnumerator *enumerator = [items objectEnumerator]; NSDictionary* item; while (item = […]

Swift:如何组合两个Dictionary实例?

如何使用Swift将[Dictionary]附加到另一个[Dictionary] ? 我正在使用AlamoFire库将JSON发送到REST server 。 词典1 let dict1: [String: AnyObject] = [ kFacebook: [ kToken: token ] ] 词典2 let dict2: [String: AnyObject] = [ kRequest: [ kTargetUserId: userId ] ] 如何将两个字典组合成一个新字典,如下所示? let parameters: [String: AnyObject] = [ kFacebook: [ kToken: token ], kRequest: [ kTargetUserId: userId ] ] 我试过dict1 += dict2但有一个编译错误。 提前致谢!

Swift读取远程通知的userInfo

我实现了一个函数来打开AlertView,当我收到这样的远程通知: func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){ var notifiAlert = UIAlertView() var NotificationMessage : AnyObject? = userInfo["alert"] notifiAlert.title = "TITLE" notifiAlert.message = NotificationMessage as? String notifiAlert.addButtonWithTitle("OK") notifiAlert.show() } 但NotificationMessage总是零。 我的JSON有效载荷如下所示: {"aps":{"alert":"Testmessage","badge":"1"}} 我正在使用Xcode 6,Swift和我正在开发的iOS8。 我现在搜查了几个小时,但没有find任何有用的信息。 通知完美地工作..如果我点击它,alertview打开。 我的问题是,我无法从userInfo获取数据。

通缉:使用AFNetworking-2进行基本身份validation的JSON / POST的最新示例

我有一个玩具应用程序,使用基本身份validation安全提交https JSON / POST。 我被告知我应该考虑使用AFNetworking。 我已经能够安装AFNetwork-2到我的XCode项目(ios7目标,XCode5)就好了。 但是这里没有一个例子似乎与当前版本的AFNetworking-2相关,而是与之前的版本相关。 AFNetworking文档非常稀less,所以我正在努力拼凑。 非AFNetworking代码看起来像这样: NSURL *url = [NSURL URLWithString:@"https://xxx.yyy.zzz.aaa:bbbbb/twig_monikers"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 10.0]; NSData *requestData = [NSJSONSerialization dataWithJSONObject: [self jsonDict] options: 0 error: nil]; [request setHTTPMethod: @"POST"]; [request setValue: @"application/json" forHTTPHeaderField: @"Accept"]; [request setValue: @"application/json" forHTTPHeaderField: @"Content-Type"]; [request setValue:[NSString stringWithFormat: @"%d", [requestData length]] forHTTPHeaderField: @"Content-Length"]; […]

JSONKit是否支持ARC,或者是否有支持ARC的分支?

根据这些评论,JSONKit不支持ARC,甚至没有在ARC环境中运行fobjc-no-arc设置: https : //github.com/johnezang/JSONKit/issues/37

把JSON放到一个数组中

当涉及到请求和JSON时,我是一个noob。 在我的应用程序中,我发送到服务器,并取回东西,所以我可以使用它当然。 我试图查找不同的东西,但没有一个真的是我所期待的。 所以我回来了似乎是格式化的JSON。 我想知道怎么做是把它放到一个NSMutable数组。 我得到这个JSON的方式是使用AFNetworking的AFJSONRequestOperation。 我的回应是这样的。 { id = 38; name = "St. Martin Hall"; }, { id = 40; name = "Assumptions Commons"; }, { id = 41; name = "Vickroy Hall"; }, { id = 42; name = "St. Ann Hall"; }, { id = 37; name = "Duquesne Towers"; }

在Objective-C中parsingJSON中的JSON

我试图存储JSON中的JSON,我从以下请求中获得… NSURL *URL = [NSURL URLWithString:@"http://www.demo.com/server/rest/login?username=admin&password=123"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; [request setHTTPMethod:@"GET"]; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { // Handle error… return; } if ([response isKindOfClass:[NSHTTPURLResponse class]]) { NSLog(@"Response HTTP Status code: %ld\n", (long)[(NSHTTPURLResponse *)response statusCode]); NSLog(@"Response HTTP Headers:\n%@\n", […]

如何parsing收到的回复

我对iOS应用程序开发非常陌生,我从服务器获取下面的响应: "[{\"EmployeeID\":\"000001\",\"EmplyeeName\":\"ABCD EFGHI\"}, {\"EmployeeID\":\"000002\",\"EmplyeeName\":\"ADGHT ASASASAS\"}]" 请有人帮助我如何在我的应用程序中使用员工ID和员工姓名。