我是 RESTKIT 的初学者,最近才在来自 ray 的教程http://www.raywenderlich.com/13097/intro-to-restkit-tutorial的foursquare公共api上对其进行了测试。
虽然我明白了它的要点,但有些部分我不明白,并希望得到它的指针,以便我可以使用我自己的 Web 服务。
- (void)viewDidLoad
{
[super viewDidLoad];
RKURL *baseURL = [RKURL URLWithBaseURLString:@"https://api.Foursquare.com/v2"];
RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];
objectManager.client.baseURL = baseURL;
RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[Venue class]];
[venueMapping mapKeyPathsToAttributes:@"name", @"name", nil];
[objectManager.mappingProvider setMapping:venueMapping forKeyPath:@"response.venues"];
[self sendRequest];
}
我该如何改变
[venueMapping mapKeyPathsToAttributes:@"name", @"name", nil];
[objectManager.mappingProvider setMapping:venueMapping forKeyPath:@"response.venues"];
容纳我自己的webMethod?(我的 webMethod 如下所示)
目前,我将文件上传到 IIS 以进行测试,并使用 IP 进行 Web 服务。(我经常更换工作区,所以我将其指定为 myIPAddress 以便于沟通)
-- 我的服务代码(更改编辑:现在返回 JSON)
[WebMethod]
[ScriptMethod( ResponseFormat = ResponseFormat.Json)]
public void testTextJSON()
{
string text = "Testing for Json!";
List<string> arrayList = new List<string>();
arrayList.Add(text);
JavaScriptSerializer js = new JavaScriptSerializer();
string name = js.Serialize(arrayList);
Context.Response.Write(name);
}
返回 -["Testing for Json!"]
编辑-我目前更改的内容viewDidLoad
并sendRequest
测试我自己的服务
- (void)viewDidLoad
{
[super viewDidLoad];
RKURL *baseURL = [RKURL URLWithBaseURLString:@"http://192.168.1.12"];
RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];
objectManager.client.baseURL = baseURL;
RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[venue class]];
[venueMapping mapKeyPathsToAttributes:@"name", @"name", nil];
[self sendRequest];
}
和
- (void)sendRequest
{
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKURL *URL = [RKURL URLWithBaseURL:[objectManager baseURL] resourcePath:@"/webService/webService1.asmx/testTextJSON"];
objectManager.acceptMIMEType = RKMIMETypeJSON;
objectManager.serializationMIMEType = RKMIMETypeJSON;
[[RKParserRegistry sharedRegistry] setParserClass:[RKJSONParserJSONKit class] forMIMEType:@"text/plain"];
[objectManager loadObjectsAtResourcePath:[NSString stringWithFormat:@"%@", [URL resourcePath]] delegate:self];
}
编辑 n+1 - 这是我的一些错误信息,也许有人可以告诉我出了什么问题?
2012-11-25 06:49:20.925 fourSquareAPI[352:12e03] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x8354430> valueForUndefinedKey:]: this class is not key value coding-compliant for the key venues.'
如果我删除[objectManager.mappingProvider setMapping:venueMapping forKeyPath:@"venues"];
我会得到
2012-11-25 06:52:47.495 fourSquareAPI[368:11603] response code: 200
2012-11-25 06:52:47.499 fourSquareAPI[368:12e03] W restkit.object_mapping:RKObjectMapper.m:87 Adding mapping error: Could not find an object mapping for keyPath: ''
2012-11-25 06:52:47.499 fourSquareAPI[368:12e03] E restkit.network:RKObjectLoader.m:231 Encountered errors during mapping: Could not find an object mapping for keyPath: ''
2012-11-25 06:52:47.502 fourSquareAPI[368:11603] Error: Could not find an object mapping for keyPath: ''
有人可以教我怎么做吗??任何帮助将不胜感激,我真的很想学习如何使用 RESTKIT 来使用 web 服务。