Tag: json

如何在我的应用程序中使用ORKESerializer?

我正在开发我的第一个ResearchKit应用程序。 我一直在看这个video 。 其中一种对我有用的技术是将调查结果序列化为JSON。 video中使用的方法是ORKESerializer.JSONDataForObject(taskResult) 。 他解释说,这不是研究套件的标准部分,但它被包含在GitHub上的一个名为ORKTest的testing应用程序中。 我设置了我的taskViewController委托,就像他在video上设置的那样: extension ViewController : ORKTaskViewControllerDelegate { func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) { switch reason { case .Completed: let taskResult = taskViewController.result let jsonData = try! ORKESerializer.JSONDataForObject(taskResult) if let jsonString = NSString(data: jsonData, encoding: NSUTF8StringEncoding) { print(jsonString) } break case .Failed, .Discarded, .Saved: break } //Handle […]

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 […]

无法parsing来自谷歌的json响应

我正试图从这个URLparsingJson响应。 我已经使用了SBJsonParser,MTJSON和另一个parsing器,但是我在这三种情况下都得到了NULL。 apiUrlStr = @"http://maps.google.com/maps?output=dragdir&saddr=Delhi&daddr=Mumbai+to:hyderabad"; NSURL* apiUrl = [NSURL URLWithString:apiUrlStr]; NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl encoding:NSUTF8StringEncoding error:nil]; SBJsonParser *json = [[[SBJsonParser alloc] init] autorelease]; NSDictionary *dictionary = [json objectWithString:apiResponse]; NSLog(@"dictionary=%@", [json objectWithString:apiResponse]); 2011-12-09 16:59:01.226 MapWithRoutes [2523:207] dictionary =(null) Plzbuild议我一些东西

错误域= NSCocoaErrorDomain代码= 3840“JSON文本没有开始数组或对象和选项允许片段没有设置。

错误types:错误域= NSCocoaErrorDomain代码= 3840“JSON文本没有开始数组或对象和选项,以允许片段没有设置。”。UserInfo = {NSDebugDescription = JSON文本没有开始与数组或对象和选项,以允许片段组。 场景:Bonjour Server能够将JSON数据成功发送到客户端。 但偶尔我看到这些错误: Error Domain=NSCocoaErrorDomain Code=3840 。 任何人都可以build议如何解决这个问题?

我需要在ios中的键没有双引号的jsonstring

我像上传jsonstring到服务器 NSDictionary *values = [[NSDictionary alloc]initWithObjectsAndKeys:@"name", @"objective", nil]; NSArray *array = [[NSArray alloc]initWithObjects:values,nil]; NSDictionary *result = [[NSDictionary alloc]initWithObjectsAndKeys:array, @"objectives", nil]; 我使用下面的代码将字典转换为JSON: id obj = result; NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:obj options:kNilOptions error:&error]; NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 我得到正确的JSON { "objectives":[ {"objective":"name"} ] } 这是正确的JSON,但我需要像JSONstring { objectives:[ {"objective":"name"}] } 是否有可能在iOS中的密钥创build没有双引号 ? 只有这个JSONstring,我们得到的答复,否则我得到错误。

AFNetworking v3.1.0 multipartFormRequestWithMethod上传带引号的JSON数值

当我使用AFNetworking v3.1.0 multipartFormRequestWithMethod上传文件并包含一个参数字典,该参数字典被转换为JSON,并且字典中有一个条目如: ["Test": 1] 也就是说,一个带有数值的键,当它到达我的服务器时,JSON结构是一个带引号的string。 例如: {"Test":"1"} 这不是我想要的。 我想在服务器上收到的是: {"Test": 1} 请注意,当使用AFHTTPSessionManager的POST方法(我认为不允许file upload)时,我不会遇到这个问题。 这是AFNetworking中的一个错误吗? 我在做什么? 有没有解决方法或其他解决scheme? 我已经在AFNetworking JSON序列化问题上看到了这个讨论,但是我的应用程序并不适合在服务器上进行parsing,以便按照我喜欢的方式(数字不带引号)进行parsing。 思考? 这是我使用AFNetworking的客户端代码: import Foundation import SMCoreLib // some common library functions I use class Server { private let manager: AFHTTPSessionManager! internal static let session = Server() var uploadTask:NSURLSessionUploadTask? private init() { self.manager = AFHTTPSessionManager() // https://stackoverflow.com/questions/26604911/afnetworking-2-0-parameter-encoding […]

如何将带有标记的CURL命令转换成Swift?

我有我们的自定义REST API的CURL命令,除了示例CURL调用之外,没有任何其他文档。 当我在Swift中需要这个时,我怎么才能开始翻译和在Swift中工作呢? 到目前为止,我使用了SwiftyJSON(用于与其他API玩),但是我不知道如何在其中包含访问令牌。 使用CURL的示例调用 curl -k -i -H "Accept: application/jsorization: Bearer fbqgk5um9bei9newmitcjk8zqw12zw7b9" -X GET 'https://x43.herokuapp.com/x43/api/v1/sch?$aca=N' 响应 HTTP/1.1 200 OK Server: Cowboy Connection: keep-alive X-Powered-By: Express Content-Type: application/json; charset=utf-8 Date: Wed, 13 Jul 2016 15:05:28 GMT Transfer-Encoding: chunked Via: 1.1 vegur 结果在JSON中 {"result":[{"sco_id":2,"sco_type":"LS","name":"Phoenix English","city":"Perth","cou_id":"AU","environment":"R","image":"- ","rating":0},{"sco_id":3,"sco_type":"LS","name":"Milner college","city":"Perth ","cou_id":"AU","environment":"L","image":"- ","rating":0},…

视图控制器不在视图层次结构?

所以我想通过编程方式从一个视图控制器转换到另一个视图控制器,以便我只能在用户需要login时初始化它。 但是,xcode不断给我的错误,它不是在视图层次结构,并拒绝加载到它。 ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end ViewController.m #import "ViewController.h" #import "API.h" @interface ViewController () @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; if (![[API sharedInstance] isAuthorized]) { [self performSegueWithIdentifier:@"ShowLogin" sender:nil]; }// Do any additional setup after loading the view, typically from a nib. } – (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose […]

didSelectRowAtIndexPath不能与NSNotificationCenter一起使用

我有一个MasterDetail应用程序,我正在使用这将用于显示玩家(如体育)和详细统计。 玩家列表从PostgreSQL数据库调用,并使用JSONModel从JSONparsing。 到目前为止,我能够从Postgres DB获取所需的所有数据,并在MasterView中完美显示。 我正在使用NSNotificationCenter将数据从主数据传递到Detail视图(我使用MasterView中的函数获取数据)。 我能够将数据准确地传递给详细信息视图,但由于某种原因,我didSelectRowAtIndexPath不能正常工作。 我显然做错了,但我不知道它是什么。 这里是代码的重要部分: 在MasterViewController.m中的viewDidAppear: -(void)viewDidAppear:(BOOL)animated { //fetch the feed from the Postgres Database [JSONHTTPClient getJSONFromURLWithString:@"http://myurl" completion:^(NSDictionary *json, JSONModelError *err) { NSError* error = nil; _feed = [[PostgresFeed alloc]initWithDictionary:json error:&error]; //Print the data fethced to NSLog in JSON format NSLog(@"Players: %@", _feed.players); [[NSNotificationCenter defaultCenter] postNotificationName:@"myNotification" object:nil userInfo:json]; //reload the table view […]

在iOS应用程序中parsingjson

我有这样的rest回应 { "data": [ { "id": "adhoc_Expense_process:1:43", "key": "adhoc_Expense_process", "name": "Expense process", "version": 1, "deploymentId": "10", "resourceName": "org\/activiti\/examples\/adhoc\/Expense_process.bpmn20.xml", "diagramResourceName": "org\/activiti\/examples\/adhoc\/Expense_process.png", "startFormResourceKey": null, "graphicNotationDefined": "true" }, {. . . }, ] } 我正在处理这样的回应。 – (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response { if ([request isGET]) { // Handling GET /foo.xml if ([response isOK]) { // Success! Let's take a look at […]