I have a problem parsing the array of objects from the JSON result.
[
{
\"first_name\":\"vijay\",
\"last_name\":\"last\",
\"credi
Google "JSON Framework". Follow the (easy) instructions to install it.
Then go:
//let's say there's NSString *jsonString.
NSArray *userData = [jsonString JSONValue];
NSMutableArray *creditCards = [NSMutableArray array];
for (NSDictionary *user in userData) {
[creditCards addObject:[user objectForKey:@"creditCardNumber"]];
}
You'll drop out the bottom of that with NSMutableArray *creditCards full of NSString objects containing the credit card numbers.
@Dan Ray answer is correct, but if you want to avoid third-party librairies you can use NSJSONSerialization
:
Assuming that NSData *responseData
is containing your JSON.
NSArray *userData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:nil];
NSMutableArray *creditCards = [NSMutableArray array];
for (NSDictionary *user in userData) {
[creditCards addObject:[user objectForKey:@"creditCardNumber"]];
}
Source: NSJSONSerialization.