該參數需要一個NSDictionary
,它將被轉換爲URL中的鍵/值對。所以,關鍵是容易的,但你必須先在字典中設置它之前將它轉換成JSON值...
NSDictionary *jsonDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
@"Sean Plott", @"playerName",
[NSNumber numberWithBool:NO], @"cheatMode", nil];
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:0 error:&error];
if (!jsonData) {
NSLog(@"NSJSONSerialization failed %@", error);
}
NSString *json = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSDictionary *parameters = [[NSDictionary alloc] initWithObjectsAndKeys:
json, @"where", nil];
如果我們假設您的客戶端配置是這樣的(通常你繼承AFHTTPClient
並且可以移動這些東西里面
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.parse.com/"]];
[client setDefaultHeader:@"X-Parse-Application-Id" value:@"Q82knolRSmsGKKNK13WCvISIReVVoR3yFP3qTF1J"];
[client setDefaultHeader:@"X-Parse-REST-API-Key" value:@"iHiN4Hlw835d7aig6vtcTNhPOkNyJpjpvAL2aSoL"];
[client registerHTTPOperationClass:[AFJSONRequestOperation class]];
那麼你應該能夠調用
[client getPath:@"1/classes/GameScore"
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failed %@", error);
}];
Day9把我帶到這裏! – dgrandes