0

That may sound odd.

I got an NSString value NSString * numb = [self.dataDict valueForKey:@"id"]; and i know, that is it some kind of integer (for example, i need that integer to comparison - if val less or equal then something). I need to know what integer is it.

What i've tried:

   NSNumber *numba = [self.dataDict valueForKey:@"id"];

NSLog output - numba is 2038735264

And actually that was 428.

is there any way to achieve the point? Thanks!

That is piece of responseObject:

( { id = 3; dog = "\U041a\U0430\U043a\U043e\U0439-\U0442\U043e \U043c\U0443\U0434\U0430\U043a \U043d\U0430\U043a\U0440\U0443\U0442\U0438\U043b"; image = "cute_dog/116.jpg"; score = 586; }, { id = 115; dog = "\U0422\U0430\U043d\U044f \U041a\U043b\U044e\U043a\U0432\U0438\U043d\U0430"; image = "cute_dog/115.jpg"; score = 481; },

11
  • Can you post the console output of the whole dictionary object? Commented Feb 27, 2015 at 19:18
  • Are you sure the value at "id" is an NSNumber? Commented Feb 27, 2015 at 19:19
  • 1
    You used %d for the format in NSLog, right? Commented Feb 27, 2015 at 19:22
  • Yes value of id is number, it come from JSON array. Commented Feb 27, 2015 at 19:24
  • Code updated. Please take a look Commented Feb 27, 2015 at 19:24

2 Answers 2

6

There are a number of methods you can use to convert an NSString to a number. What numeric type would you like?

NSString *string = self.dataDict[@"id"];
int intValue = string.intValue;
NSInteger integerValue = string.integerValue;
long long longLongValue = string.longLongValue;
Sign up to request clarification or add additional context in comments.

1 Comment

Best answer, i'l definitely need to remember that.
1

Trying something like this.

NSNumber *numba = [NSNumber numberWithInt[self.dataDict valueForKey:@"id"]];
//For string
NSString *stringValue = [numba stringValue];
//For integer
NSInteger integer = [numba integerValue];

4 Comments

I was just providing options. One NSString and one NSInteger
Thank for help kylecman, but it still display values like 2048698912
I thought I did one step...NSNumber to NSString and NSNumber to NSInteger.
@kylecman Sorry. I read your answer incorrectly. Ignore everything I said earlier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.