-5

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?

1
  • 5
    Welcome to Stack Overflow, before you post a question here, please read the How to Ask page, for tips on posting. Commented Apr 22, 2015 at 21:50

2 Answers 2

1

try NSJSONSerialization and assign it to a variable of type id and you could cast it like using (NSArray) or you could directly assign it to variable of type NSArray from NSJsonserialization

Sign up to request clarification or add additional context in comments.

Comments

0

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];

Source

Method 2

NSObject *o =[NSJSONSerialization JSONObjectWithData:data 
                                             options:NSJSONReadingMutableContainers 
                                               error:&error];

NSArrary *arr=(NSArray*)o;

Source

Comments

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.