I have a problem getting the values of PHP JSON into an NSArray.
These are the values I get from my JSON: '1451', '1450', '1449'.
How can I convert this into an NSArray?
I have a problem getting the values of PHP JSON into an NSArray.
These are the values I get from my JSON: '1451', '1450', '1449'.
How can I convert this into an NSArray?
Method 1
NSString * jstring = @"[1451,1450,1449]"; //your json string
jstring = [jstring stringByReplacingOccurrencesOfString:@"[" withString:@""];
jstring = [jstring stringByReplacingOccurrencesOfString:@"]" withString:@""];
NSArray * intArray = [string componentsSeparatedByString:@","];
//you could create your int from the array like this
int x = [[intArray objectAtIndex:0]intValue];
Method 2
NSObject *o =[NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:&error];
NSArrary *arr=(NSArray*)o;