如何从 json-rpc Web 服务获取数据:iPad /iPhone / Objective C
我正在开发一个 iPad 项目,该项目需要与 json-rpc Web 服务通信。 Web 服务基于 Drupal,带有模块:cck 和视图
1)我需要将 json 对象推送到 Web 服务中 2)我需要来自网络服务的回调数据
,我已经实现了 SBJSON api 和 https://github.com /samuraisam/DeferredKit/ iPad 项目的 api。
SBJSON api 工作正常,我理解这个 Samuriaisam DefferedKit 对我来说是新的
我的问题是如何从这个 json-rpc Web 服务中获取数据,有人有一些示例代码吗?或者在一些地方我可以找到 Objective C - json-rpc webservice 文档。
亲切的问候,
Bart Schoon
---------更新--------
我现在使用此代码:
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"}
---------/Update--------
出了什么问题?有人有这方面的经验吗?
亲切的问候,
Bart Schoon
I'am working on a iPad project and this project needs to talk to a json-rpc webservices. The webservices is based on Drupal with module : cck and views
1)I need to push a json object into the webservice
2)I need the callback data from the webservice
I already have implemented the SBJSON api and the https://github.com/samuraisam/DeferredKit/ api to the iPad project.
The SBJSON api works fine and I understand this one
The Samuriaisam DefferedKit is new for me
My question is how to get data out of this json-rpc webservice, has someone some sample code? Or some places where I can find Objective C - json-rpc webservice documentation.
Kind Regards,
Bart Schoon
---------Update--------
I use this code now:
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);
This will result in this message from the server:
{"error":{"name":"JSONRPCError","code":-32600,"message":"The received JSON not a valid JSON-RPC Request"},"version":"1.1"}
---------/Update--------
What is wrong? Has someone experience with this?
Kind Regards,
Bart Schoon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
读取 JSON 文件获取该数据。
NSDictionary *dictionary = [jsonString JSONValue];
您将获得钥匙&值对。将该数据存储在各自的变量中。
Read JSon file get that data.
NSDictionary *dictionary = [jsonString JSONValue];
You will get key & value pair. Store that data in your respective variable.
只是不要使用 json-rpc - 保持简单并使用普通的 json 方法 json ;)
Just don't use a json-rpc - keep it simple and json the normal jSon method ;)