变量不是CFString

时间:2011-08-25 06:27:11

标签: iphone objective-c

我从JSON获得价值它给出异常var不是CFString。    下面是我从中获取数据的链接      http://www.krsconnect.no/community/api.html?method=categories&appid=620&mainonly=true

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

2 个答案:

答案 0 :(得分:0)

它可能是一个整数。用这个。

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

答案 1 :(得分:0)

我认为这个问题可以帮到你

Replace multiple characters in a string in Objective-C?

CFStringRef aCFString = (CFStringRef)aNSString;

完美而透明地运作。同样地:

NSString *aNSString = (NSString *)aCFString;