JSON文本和变量计数

时间:2012-05-12 09:34:40

标签: objective-c xcode

我正在读这样的......

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"];

NSArray *messagearray = [data objectForKey:@"message"];
NSArray *namearray    = [data objectForKey:@"name"];


NSDictionary* Dictionary = [NSDictionary dictionaryWithObjects:message forKeys:name];

for (NSString* Key in [Dictionary allKeys]){
    NSLog(@"%@ %@",Key,[Dictionary objectForKey:Key]);

}

...这个JSON文件......

{"message":["Untitled1a","Untitled2a","Untitled3a"],"name":    ["Untitled1b","Untitled2b","Untitled3b"]}

......这是结果......

Untitled3b Untitled3a
2012-05-12 11:31:17.983 Quick Homework[721:f803] Untitled1b Untitled1a
2012-05-12 11:31:17.983 Quick Homework[721:f803] Untitled2b Untitled2a

...但是对于每一对(Untitled 1b 2b)我想分配两个UITextFields,显示对应的文本......

我尝试使用这种方法:

for (NSString *string in messagearray){

}do{
    NSLog(@"happt = %i", b);
    b++;

}

while(b == b);

//While loop
while (b == b ) {
    NSLog(@"x = %i", b);
    b++;
}

}

我想计算数组中的对象,以便多次重复UITextField的alloc代码,并相应地显示文本,但我无法做到。请帮忙!!

1 个答案:

答案 0 :(得分:0)

为什么不能使用-count?

b = [messagearray count]


直接回答你的问题:

b = 0;
for (id item in messagearray)
    b++;