2012-02-02 28 views
0

我可以noob我想要的是將一個NSDictionary對象轉換爲NSInteger.im解析json對象並將其存儲在一個NSMutableArray中,然後存儲在NSDictionary對象中,稱爲boy.could you guys幫助我out.below是代碼。如何將一個NSDictionary值轉換爲NSInteger

 NSURLRequest *request = [NSURLRequest requestWithURL:jsonurl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; 
connection1=[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; 


NSLog(@"jsonurl:%@",jsonurl); 
self.jsonData=[NSData dataWithContentsOfURL:jsonurl]; 

NSDictionary *items=[NSJSONSerialization JSONObjectWithData:self.jsonData options:NSJSONReadingMutableLeaves error:nil]; 
NSLog(@"blah:%@",jsonArray); 
items1 = [items objectForKey:@"ThingsTodo"]; 

story = [[NSMutableArray array]retain]; 
media1 = [[NSMutableArray array]retain]; 

url=[[NSMutableArray array]retain]; 
media2=[[NSMutableArray array]retain]; 
descriptiondesc=[[NSMutableArray array]retain]; 
for (NSDictionary *item in items1) 
{ 
    [self.story addObject:[item objectForKey:@"Name"]]; 
    [self.media1 addObject:[item objectForKey:@"Status"]]; 
    [self.media2 addObject:[item objectForKey:@"Image"]]; 

} 
    NSDictionary *boy=[self.media1 objectAtIndex:indexPath.row]; 

回答

5

把你nsdictionary價值爲nsstring然後採取NSInteger和不喜歡:

NSInteger n = [strVal intValue]; 
+0

k會試一試... – stephensam 2012-02-02 05:19:42

+0

感謝它的工作 – stephensam 2012-02-02 05:29:40

0

更具體 「的intValue」 給出了 「INT」,而 「integerValue」 返回 「NSInteger的」,所以

NSInteger n = [strVal integerValue];