我用JSONModel從JSON捕獲數據:約NSUinteger問題和int
@interface BBTCampusBus : JSONModel
@property (strong, nonatomic) NSString * Name;
@property (assign, nonatomic) NSUInteger Latitude;
@property (assign, nonatomic) NSUInteger Longitude;
@property (nonatomic) BOOL Direction;
@property (assign, nonatomic) NSUInteger Time;
@property (nonatomic) BOOL Stop;
@property (strong, nonatomic) NSString * Station;
@property (assign, nonatomic) NSInteger StationIndex;
@property (assign, nonatomic) NSUInteger Percent;
@property (nonatomic) BOOL Fly;
@end
而且我有以下代碼:
for (int i = 0;i < [self.campusBusArray count];i++)
{
NSLog(@"index at nsuinteger - %@", (NSUInteger)self.campusBusArray[i][@"StationIndex"]);
NSLog(@"index - %lu", index);
if ([(NSUInteger)self.campusBusArray[i][[@"StationIndex"] ]== index)
{
numberOfBusesCurrentlyAtThisStation++;
}
}
其實StationIndex
是1或2位整數。例如我有self.campusBusArray[i][@"StationIndex"]
== 4,並且我有index
== 4,那麼兩個NSLog都輸出4,但它不會跳入if塊,否則將不會執行numberOfBusesCurrentlyAtThisStation++
。有人可以告訴我爲什麼嗎?
非常感謝!現在我發現我犯了這個錯誤,因爲我忘記了字典中的值必須是一個對象,所以一個NSUInteger將被裝箱到一個NSNumber中。再次感謝你! – Caesar