通过以下方式...
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat:@"/lkj/"]];
NSString *fileName = [NSString stringWithFormat:@"/sandbox/2012_05_11.json"];
[[self restClient] loadFile:fileName intoPath:path];
NSString *fileContent = [[NSString alloc] initWithContentsOfFile:path];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *data = (NSDictionary *) [parser objectWithString:fileContent error:nil];
// getting the data from inside of "menu"
NSString *message = (NSString *) [data objectForKey:@"message"];
NSString *name = (NSString *) [data objectForKey:@"name"];
namegroup.text = [NSString stringWithFormat:@"%@ %@",name, message];
...我正在尝试解析我以前用其他代码制作的文档...
{"message":["Untitled1a","Untitled2a","Untitled3a"],"name":["Untitled1b","Untitled2b","Untitled3b"]}
但是,使用上面的代码,在名称 group.text 中,这会出现......
(untitled, untitled, untitled) (untitled, untitled, untitled)
...但我想做的是分配许多 UITextFields,每个成对,(2、2、2..),一个显示名称的字段和另一个显示消息的字段,所以将 1a 与 1b 配对, 2a 和 2b... 显然这些字段不会是 Untitled1a,而是“你好吗”...
但我似乎无法解决这个问题!请帮忙!!