如何通过Get方法从WebServices中获取数据并保存到iphone sdk中的MutableDictionary中

发布于 2025-01-04 09:51:56 字数 58 浏览 2 评论 0原文

如何通过 Get 方法从 Web 服务获取数据并保存到 iPhone 中的可变字典中.....thnx

How to fetch the data from Web Services by Get Method and want to save into Mutable Dictionary in iPhone.....thnx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤蝉 2025-01-11 09:51:56

如果您使用 JSOn Web 服务来获取数据,请尝试本教程

#import 

@interface jsonViewController : UIViewController {
    IBOutlet UILabel *label;
    NSMutableData *responseData;
}


Replace the contents of jsonViewController.m with:


#import "jsonViewController.h"
#import "JSON/JSON.h"

@implementation jsonViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    responseData = [[NSMutableData data] retain];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yourwebservice.com"]];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [responseData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    label.text = [NSString stringWithFormat:@"Connection failed: %@", [error description]];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    [responseData release];

    NSArray *tempArray = [responseString JSONValue];
}

if you are using JSOn webservice to get the data then try out this tutorial

#import 

@interface jsonViewController : UIViewController {
    IBOutlet UILabel *label;
    NSMutableData *responseData;
}


Replace the contents of jsonViewController.m with:


#import "jsonViewController.h"
#import "JSON/JSON.h"

@implementation jsonViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    responseData = [[NSMutableData data] retain];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yourwebservice.com"]];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [responseData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    label.text = [NSString stringWithFormat:@"Connection failed: %@", [error description]];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    [responseData release];

    NSArray *tempArray = [responseString JSONValue];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文