0

I have problem with a NSArray object that a json service create it. in my NSArray object there is just one object and it is a number. when i debug code and watch NSArray Value with mouse over it show numbers in this format:@""1"".

when i want to convert it to int or NSNumber it return 0. i checked it with a lot of approach. and when I want to convert it to NSString and show string using NSLog or watch tool it will show it like "1".

these are some code of my efforts:

data is a NSArray Object:

NSString  *str = [data objectAtIndex:0];
NSNumber *number = [str integerValue];

int int1 =[[str stringByReplacingOccurrencesOfString:@"""" withString:@""] intValue];


number = [data objectAtIndex:0];
number = [[data objectAtIndex:0] integerValue];
Aqil
  • 360
  • 2
  • 16

1 Answers1

2

It seems that in your json, numbers are actually strings, try instead with:

int int1 =[[str stringByReplacingOccurrencesOfString:@"\"" withString:@""] intValue];
Mat
  • 7,613
  • 4
  • 40
  • 56
  • yes webservice method return a string value. so it's work know probably. but in another case that i develop before i never seen this issue. thanks a lot – Aqil Dec 16 '13 at 08:03