3

actually i have used this code for converting NstaggedpointerString to string

NSString  *index = [responseSelectedAvailibility[i] valueForKey:@"day"];

        NSLog(@"String %@",index);

        int indexDayValue = (int)index;
        NSLog(@" index %d",indexDayValue);

        indexDayValue = indexDayValue-1;

    NSLog(@" index after decrementing %d",indexDayValue);

i get output of string is like this

String

     (
        1
    )

now how i get this 1.

Mad Burea
  • 531
  • 8
  • 22
  • The problem isn't converting that string to an int, the problem is that you haven't turned on essential warnings in your compiler, so it lets you get away with this nonsense. – gnasher729 Nov 02 '16 at 12:09
  • 2
    The main issue is obviously the value-for-key-trap. – vadian Nov 02 '16 at 12:15
  • This is not a duplicate. Two different thing. This question is about a bug in the JSONDictionary parsing. A number is being parsed into an NSTaggedPointerString. Also, gnasher729 is wrong. Its a bug in how the parsing works. Long numbers are being converted properly but short numbers are not. Any other JSON parser would and does see these as numbers. – codeslapper Aug 09 '18 at 18:26

1 Answers1

3

Replace this:

int indexDayValue = (int)index;

with this:

int indexDayValue = [index intValue];

Edit:

[__NSArrayI intValue] unrecognized selector sent to instance 0x7f940053f7e0

That's because index is in fact an array, not a string. Do the following:

NSDictionary *dict = responseSelectedAvailibility[i];
NSArray *dayArray = dict[@"day"];
NSString *dayIndexString = [dayArray firstObject];
int dayIndex = [dayIndexString intValue];
alexburtnik
  • 7,661
  • 4
  • 32
  • 70