我正在做一个 iPad 项目,这个项目需要与 json-rpc 网络服务对话。 Web 服务基于 Drupal 模块:cck 和 View
1) 我需要将一个 json 对象推送到 web 服务中 2)我需要来自webservice的回调数据
我已经实现了 SBJSON api 和 https://github.com/samuraisam/DeferredKit/ api 到 iPad 项目。
SBJSON api 工作正常,我理解这个 Samuriaisam DefferedKit 对我来说是新的
我的问题是如何从这个 json-rpc 网络服务中获取数据,有人有一些示例代码吗?或者我可以在某些地方找到 Objective C - json-rpc webservice 文档。
亲切的问候,
巴特·肖恩
--------更新--------
我现在使用这段代码:
NSString *jsonString = @"{\"method\":\"views.get\",\"params\":{\"view_name\":\"client_list\",\"sessid\":\"xxxxxx\"},\"id\":1}";
NSString *requestString = [NSString stringWithFormat:@"%@",jsonString,nil];
NSLog(@"input: %@",jsonString);
NSData *requestData = [NSData dataWithBytes: [jsonString UTF8String] length: [jsonString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:@"http://subdomain.domain.com/services/json-rpc"]];
NSString *postLength = [NSString stringWithFormat:@"%d", [requestData length]];
[request setHTTPMethod: @"POST"];
[request setValue:@"Content-type: application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:requestData];
//Data returned by WebService
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
NSLog(@"output: %@",returnString);
这将导致来自服务器的消息:
{"error":{"name":"JSONRPCError","code":-32600,"message":"The received JSON not a valid JSON-RPC Request"},"version":"1.1"}
--------/更新--------
怎么了?有人有这方面的经验吗?
亲切的问候,
巴特·肖恩
最佳答案
读取 JSON 文件获取该数据。
NSDictionary *dictionary = [jsonString JSONValue]; 您将获得键值对。将该数据存储在您各自的变量中。
关于iphone - 如何从 json-rpc web 服务 : iPad/iPhone/Objective C 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4488319/