2011-08-25 81 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

相关问题