【发布时间】:2011-11-29 06:31:08
【问题描述】:
我有这个有用户名和密码的应用程序。但是我需要让它登录到特定站点并添加用户并检查配置文件..我被告知我必须使用 GET 来添加用户或查询并解析 json 中的返回数据。
我将采取哪些具体步骤?
我已经尝试了一些方法,但它确实没有任何帮助
我在谷歌上搜索过,但似乎我找到的不是我需要的。
提前谢谢:)
PS:我是编程新手,所以请对我温柔一点。(直接进入 ios 开发。)
我已经创建了应用程序,它是这样的
编辑: 我稍微修改了一下
- (IBAction)getDataPressed
{
if([myRequest_ isExecuting])
{
return;
}
if(myRequest_ != nil)
{
[myRequest_ release];
}
myRequest_ = [[ASIHTTPRequest alloc]initWithURL:[NSURL URLWithString:URL_PATH]];
myRequest_.delegate = self;
[myRequest_ startAsynchronous];
}
#pragma ASI Delegate methods
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"Request finished successfully");
NSLog(@"%@",[request responseString]);
NSDictionary *responseDictionary = [[request responseString]JSONValue];
NSDictionary *arrayElement = [responseDictionary objectForKey:@"user"];
NSString *ID = [arrayElement valueForKeyPath:@"id"];
NSLog(@"id: %d",ID);
NSString *usr = [arrayElement valueForKeyPath:@"usr"];
NSLog(@"usr: %@",usr);
NSString *gd = [arrayElement valueForKeyPath:@"gd"];
NSLog(@"gd: %@",gd);
NSString *age = [arrayElement valueForKeyPath:@"ag"];
NSLog(@"ag: %@",age);
NSString *st = [arrayElement valueForKeyPath:@"st"];
NSLog(@"st: %@",st);
NSString *lf = [arrayElement valueForKeyPath:@"lf"];
NSLog(@"lf: %@",lf);
NSString *da = [arrayElement valueForKeyPath:@"da"];
NSLog(@"da: %d",da);
for(NSString *value in [arrayElement allValues]){
NSLog(@"Found Value %@",value);
label.text = value;
[value release];
[super release];
}
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSLog(@"Request failed");
}
-(void)dealloc {
[super dealloc];
}
@end
在获取值时仍然是相同的,但是当我在应用程序上按下获取数据时。它关闭。我需要帮助。谢谢,我希望将值张贴在标签上
【问题讨论】:
-
您使用的网站是否提供任何 API?通常 POST 请求用于向服务器提供数据。该网站可能也在使用 oauth。
-
@Nilesh - 是的,他们确实有 API
-
我使用 NSZombieEnabled,它说
2011-12-06 15:22:06.301 APITextProject[3705:207] *** -[APITextProjectViewController dealloc]: message sent to deallocated instance 0x5a516c0