如何将 NSDictionary 值转换为 NSInteger

发布于 2025-01-01 09:53:18 字数 1154 浏览 0 评论 0原文

我是菜鸟,我想要的是将 NSDictionary 对象转换为 NSInteger.im 解析 json 对象并将其存储在 NSMutableArray 中,然后将其存储在名为 boy 的 NSDictionary 对象中。你们可以帮我吗?下面是代码。

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

I m a noob what i want is to convert a NSDictionary object to NSInteger.i m parsing json objects and storing it in an NSMutableArray,which is then stored in NSDictionary object called boy.could you guys help me out.below is the code.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慕烟庭风 2025-01-08 09:53:18

将您的 nsdictionary 值放入 nsstring 中,然后采用 NSInteger 并执行以下操作:

NSInteger n = [strVal intValue];

Put your nsdictionary value into nsstring and then take an NSInteger and do like :

NSInteger n = [strVal intValue];
尽揽少女心 2025-01-08 09:53:18

更具体地说,“intValue”给出“int”,而“integerValue”返回“NSInteger”,所以

NSInteger n = [strVal integerValue];

To be more specific "intValue" gives "int" while "integerValue" returns "NSInteger" so

NSInteger n = [strVal integerValue];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文