0

I am getting value from JSON it gives exception var is not CFString. below is the link from which i am getting data http://www.krsconnect.no/community/api.html?method=categories&appid=620&mainonly=true

NSString *test = aBook.catId;

Book Class

@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
ali
  • 85
  • 3
  • 10

2 Answers2

0

Its an integer maybe. Use this.

   NSString* test = [NSString stringWithFormat:@"%d",aBook.catId];
mayuur
  • 4,736
  • 4
  • 30
  • 65
  • its giving wrong value using this can you pleas check the json data in which catid is given so that you can get idea to store that – ali Aug 25 '11 at 06:41
  • print the value of aBook.catId using NSLog(@"%@",aBook.catId) and let me know what it comes. – mayuur Aug 25 '11 at 06:47
  • { "categoryId": 202, "name": "Sport" } cat id is given in this way and i am storing it in NSString – ali Aug 25 '11 at 07:06
  • can you post the code about how you are giving value to aBook.catId? – mayuur Aug 25 '11 at 07:39
  • its because you have declared the catId as NSString. in the header file declare catId as NSInteger and it should work. – mayuur Aug 25 '11 at 08:43
0

I think this question should help you

Replace multiple characters in a string in Objective-C?

CFStringRef aCFString = (CFStringRef)aNSString;

works perfectly and transparently. Likewise:

NSString *aNSString = (NSString *)aCFString;
Community
  • 1
  • 1
PJR
  • 13,052
  • 13
  • 64
  • 104