IOS / Objective-C: Get Number from JSON

I have a JSON dictionary that contains what I will call an integer (in math), i.e. 1.

I would like to store this number in the master data attribute, which is NSInteger. The following code issues a warning:

Incompatible pointer to an integer Initializing an NSInteger conversion with an expression of type 'id'

 NSInteger insertID = jsonResults[@"insert_id"];

I have tried various combinations int, NSNumberetc. to no avail. Can anyone suggest the right way to do this?

+4
source share
2 answers

NSDictionarycan't store NSInteger. He stores NSNumber. Therefore you need to deploy NSNumber:

NSInteger insertID = [jsonResults[@"insert_id"] integerValue];
+5

. eaxample

:

insert_id = @(100)//, 100 - insert_id

:

NSInteger insertID = [jsonResults [@ "insert_id" ] intValue];

+1

Source: https://habr.com/ru/post/1614053/


All Articles