I have the next php script:
<?PHP
$results = array(
array(
'col1'=>'val1.1',
'col2'=>'val1.2'
),
array(
'col1'=>'val2.1',
'col2'=>'val2.2'
)
);
echo json_encode($results);
?>
Every array from the main array represents a raw from a database. The results variable is sent to an OSx app. I'm trying to decode the json string to sync a local database with a remote database.
I'm using this code:
NSError *error = nil;
id object = [NSJSONSerialization
JSONObjectWithData:receivedData
options:0
error:&error];
if(error) { /* JSON was malformed, act appropriately here */ }
if([object isKindOfClass:[NSDictionary class]]){
NSDictionary *results = object;
NSLog(@"%@",results);
}else{
NSLog(@"there is not an JSON object");
}
The problem is the app is not recognise the received string as an object. Can some one explain me why and what I'm doing wrong?
The string received is:
[{"col1":"val1.1","col2":"val1.2"},{"col1":"val2.1","col2":"val2.2"}]