0
EDIT:URLが文字列によって送信されていることがわかりましたので、NSURL
に変更し、データの一部を解析して「NSUnknownKeyException
」とSIGABRT
にヒットしました。残りのコードは同じです...ありがとう!!iOS -NSUnknownKeyExceptionをXML解析する
こんにちは、iOSで動作している簡単なXMLパーサーを取得しようとしています。そして、私はエラーで、メインでSIGABRT
を取得し、私はそれを実行するたび:NSInvalidArgument
は、私は簡単なチュートリアルを使用し、ここで私のXMLParser
です:
#import "XMLParser.h"
#import "Video.h"
@implementation XMLParser
@synthesize video, videos;
- (XMLParser *) initXMLParser {
//[super init];
// init array of user objects
videos = [[NSMutableArray alloc] init];
return self;
}
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"video"]) {
NSLog(@"video element found – create a new instance of User class...");
video = [[Video alloc] init];
//We do not have any attributes in the user elements, but if
// you do, you can extract them here:
// user.att = [[attributeDict objectForKey:@"<att name>"] ...];
}
}
// XMLParser.m
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (!currentElementValue) {
// init the ad hoc string with the value
currentElementValue = [[NSMutableString alloc] initWithString:string];
} else {
// append value to the ad hoc string
[currentElementValue appendString:string];
}
NSLog(@"Processing value for : %@", string);
}
//XMLParser.m
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"videos"]) {
// We reached the end of the XML document
return;
}
if ([elementName isEqualToString:@"video"]) {
// We are done with user entry – add the parsed user
// object to our user array
[videos addObject:video];
// release user object
// [video release];
video = nil;
} else {
// The parser hit one of the element values.
// This syntax is possible because User object
// property names match the XML user element names
[video setValue:currentElementValue forKey:elementName];
}
// [currentElementValue release];
currentElementValue = nil;
}
@end
// end of XMLParser.m file
これは得るために、私video.hファイルです私のデータ型のアイデア..
も、これはiOSの5 にあり、ここで私のXMLであることに注意して
#import <UIKit/UIKit.h>
@interface Video : NSObject {
NSInteger videoID;
NSString *videotitle; //Same name as the Entity Name.
NSString *description; //Same name as the Entity Name.
NSString *userid;
NSString *uploadtime;
NSString *channel;
NSInteger *viewed;
NSInteger *liked;
NSString *videosource;
NSString *smallthumbnail; //Same name as the Entity Name.
NSString *largethumbnail;
}
@property (nonatomic, readwrite) NSInteger videoID;
@property (nonatomic, retain) NSString *videotitle;
@property (nonatomic, retain) NSString *description;
@property (nonatomic, retain) NSString *userid;
@property (nonatomic, retain) NSString *uploadtime;
@property (nonatomic, retain) NSString *channel;
@property (nonatomic, readwrite) NSInteger *viewed;
@property (nonatomic, readwrite) NSInteger *liked;
@property (nonatomic, retain) NSString *videosource;
@property (nonatomic, retain) NSString *smallthumbnail;
@property (nonatomic, retain) NSString *largethumbnail;
@end:ビデオクラスで
<videos>
<video id="1">
<videotitle>Lync - Find and Add a Contact</videotitle>
<description>Training tutorial for Lync</description>
<userid>USER.CORP_LDAP.i818800</userid>
<uploadtime>1321555939598</uploadtime>
<channel/>
<viewed>0</viewed>
<liked>0</liked>
<videosource>
https://saptube.pal.sap.corp/vod/media/FINAL_FindAndAddAcontact20111117105156.mp4
</videosource>
<smallthumbnail>
https://saptube.pal.sap.corp/vod/rtmp/FINAL_FindAndAddAcontact20111117105156.jpg
</smallthumbnail>
<largthumbnail>
https://saptube.pal.sap.corp/vod/rtmphd/FINAL_FindAndAddAcontact20111117105156.jpg
</largthumbnail>
</video>
</videos>
あなたはsigbartのライン/ポジションを教えてください。 – Pfitz