【发布时间】:2011-07-31 09:15:06
【问题描述】:
这是我的代码,但它不起作用
NSError *theError = nil;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.bbblllaaahhh.com"]];
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError];
NSMutableString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
self.city = [[NSMutableArray arrayWithArray:[string componentsSeparatedByString:@"\""]] JSONValue];
这里是 JSON 文本
[
{
"kanji_name":"\u30ac\u30fc\u30c7\u30f3\u30d5\u30a3\u30fc\u30eb\u30ba\u3000\u3068\u306d\u308a\u516c\u5712BigBell"
}
]
它在self.city line中报告,我该怎么办??
是的!我完全修复了这是我的修复代码
NSError *theError = nil;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.blahblah.com"]];
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError];
NSMutableString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSDictionary *jsonDict = [string JSONValue];
NSArray *jsonArray = [NSArray arrayWithArray:(NSArray *)[jsonDict valueForKey:@"kanji_name"]];
NSMutableString *text = [[NSMutableString alloc] init];
[text appendFormat:@"%@",[jsonArray objectAtIndex:0]];
self.city = [NSMutableArray arrayWithObject:text];
【问题讨论】:
-
编辑您的问题以显示您正在解析的 JSON 字符串的相关摘录(包括顶级对象)。
-
感谢您对新手的帮助:)
-
能否提供错误信息?
-
这是我的代码帖子和代码注释中的错误。 -[__NSArrayM JSONValue]:由于未捕获的异常“NSInvalidArgumentException”,无法识别的选择器发送到实例 0x5854280 正在终止应用程序,原因:“-[__NSArrayM JSONValue]:无法识别的选择器发送到实例 0x5854280”