嘿,任何人都可以请帮帮我。我是 xcode 的新手(目标 c),我正在使用 asp.net Web 服务,我只是将该服务中的 3 个文件名返回到我的 xcode 项目中。现在我想做的是解析生成的 Web 服务数据以 XML 格式转换为 xcode 中的简单字符串。
我的 xml 字符串是
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<string>Desert.jpg</string>
<string>Koala.jpg</string>
<string>Tulips.jpg</string>
</ArrayOfString>
我在 ma xcode 项目中有四个类文件,如下所示
图像保存测试视图控制器.m 文件
//
// ImageSaveTestViewController.m
// ImageSaveTest
//
// Created by Kiichi Takeuchi on 4/4/10.
// Copyright ObjectGraph LLC 2010. All rights reserved.
//
#import "ImageSaveTestViewController.h"
@implementation ImageSaveTestViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *urlString = @"http://192.168.3.106/local_storage/Webservice1.asmx/HelloWorld";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod: @"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSError *errorReturned = nil;
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&errorReturned];
if (errorReturned)
{
//...handle the error
}
NSString *retVal = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
**NSLog(@"%@", retVal);**
//this is the retval which i want to convert in simple string.its containig that above xml file
//...do something with the returned value
NSLog(@"Downloading...");
// Get an image from the URL below
id path = @"http://192.168.3.106/chmall/images/1.jpg";
NSURL *url1 = [NSURL URLWithString:path];
NSData *data11=[NSData dataWithContentsOfURL:url1];
UIImage *img1=[[UIImage alloc] initWithData:data11];
//UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"192.168.3.106/chmall/images/1.jpg"]]];
NSLog(@"%f,%f",img1.size.width,img1.size.height);
// Let's save the file into Document folder.
// You can also change this to your desktop for testing. (e.g. /Users/kiichi/Desktop/)
NSString *docDir = @"/Users/niketkapadia/Desktop";
//NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
// If you go to the folder below, you will find those pictures
NSLog(@"%@",docDir);
NSLog(@"saving png");
NSString *pngFilePath = [NSString stringWithFormat:@"%@/test.png",docDir];
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(img1)];
[data1 writeToFile:pngFilePath atomically:YES];
NSLog(@"saving jpeg");
NSString *jpegFilePath = [NSString stringWithFormat:@"%@/test.jpeg",docDir];
NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(img1, 1.0f)];//1.0f = 100% quality
[data2 writeToFile:jpegFilePath atomically:YES];
NSLog(@"saving image done");
[img1 release];
}
@end
appdeleget.m 文件
// ImageSaveTestAppDelegate.m
// ImageSaveTest
//
// Created by Kiichi Takeuchi on 4/4/10.
// Copyright ObjectGraph LLC 2010. All rights reserved.
//
#import "ImageSaveTestAppDelegate.h"
#import "ImageSaveTestViewController.h"
@implementation ImageSaveTestAppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
delagte.h 文件
//
// ImageSaveTestAppDelegate.h
// ImageSaveTest
//
// Created by Kiichi Takeuchi on 4/4/10.
// Copyright ObjectGraph LLC 2010. All rights reserved.
//
#import <UIKit/UIKit.h>
@class ImageSaveTestViewController;
@interface ImageSaveTestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ImageSaveTestViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet ImageSaveTestViewController *viewController;
@end
视图控制器.h
//
// ImageSaveTestViewController.h
// ImageSaveTest
//
// Created by Kiichi Takeuchi on 4/4/10.
// Copyright ObjectGraph LLC 2010. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ImageSaveTestViewController : UIViewController {
}
@end