ねえ、誰でも助けてください。私はxcode(目的のc)で新しく、asp.net Webサービスを使用しています。そのサービスから3つのファイル名をxcodeプロジェクトに返すだけです。今、私がやりたいことは解析することですXML の結果の Web サービス データを 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プロジェクトに次の4つのクラスファイルがあります
imagesavetestviewcontroller.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
viewcontroller.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