0

我想知道如何解析 JSON 直到没有其他内容?

这是我的代码,但我需要其他东西来满足我的条件......

 for (int i = 0; i != 7; i++)
        {
            Boxes *boxes = [NSEntityDescription insertNewObjectForEntityForName:@"Boxes" inManagedObjectContext:context];
            boxes.name =   [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"name"] ;
            boxes.sexe =   [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"sexe"] ;
            boxes.topic =   [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"topic"] ;
            boxes.number = [NSNumber numberWithInt:[[[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"number"] intValue]];
        }
4

1 回答 1

0

只需获取 boxDetail 对象的计数。

int count = [[json objectForKey:@"boxesDetail"] count];
 for (int i = 0; i < count; i++)
        {
            Boxes *boxes = [NSEntityDescription insertNewObjectForEntityForName:@"Boxes" inManagedObjectContext:context];
            boxes.name =   [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"name"] ;
            boxes.sexe =   [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"sexe"] ;
            boxes.topic =   [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"topic"] ;
            boxes.number = [NSNumber numberWithInt:[[[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"number"] intValue]];
        }
于 2012-05-15T12:37:13.307 回答