2011-08-25 64 views
0

我從JSON獲得價值它給出異常var不是CFString。 下面是從我收到數據 http://www.krsconnect.no/community/api.html?method=categories&appid=620&mainonly=true變量不是一個CFString

NSString *test = aBook.catId鏈路;

圖書類

@interface Book : NSObject { 


NSString *catId; 


NSString *name; 

}

@property(nonatomic,retain)NSString*catId; 

@property(nonatomic,retain) NSString *name; 

@end 





    #import "Book.h" 


    @implementation Book 


    @synthesize catId,name; 


    -(id)init{ 

    self=[super init]; 

    } 

    - (id)initWithDictionary:(NSDictionary*) dict { 


self.catId = [dict valueForKey:@"categoryId"]; 
self.name = [dict valueForKey:@"name"]; 




     return self; 



     } 

    - (void)dealloc { 
    [catId release]; 
    [name release]; 
    [super dealloc]; 
    } 


    @end 
+1

如果這不是一個字符串,可以是一些其他對象,如* NSNumber *。 – EmptyStack

+0

它不是字符串,所以你必須做鑄造,將其存儲在字符串 –

+0

使用[NSString stringWithFormat:] – Nitish

回答

0

它也許整數。用這個。

NSString* test = [NSString stringWithFormat:@"%d",aBook.catId]; 
+0

它提供了錯誤的價值,使用這個你可以請求檢查jtid數據中給出了catid,以便你可以有想法存儲 – ali

+0

使用NSLog(@「%@」,aBook.catId)打印aBook.catId的值,並讓我知道它是什麼。 – mayuur

+0

它給出183411 – ali

相關問題