I have an iOS app that runs this code:
userDict = [[NSDictionary alloc] initWithDictionary:[SantiappsHelper fetchInfoForUDID:@"1"]];
which goes to call this class:
- (NSDictionary*)fetchInfoForUDID:(NSString *)udid{ NSString *urlString = [NSString stringWithFormat:@"http://www.server.com/app/getusers.php"]; NSLog(@"This is the urlString from (fetchInfoForUDID) SantiappsHelper:%@",urlString); NSURL *url = [NSURL URLWithString:urlString]; return [self fetchJSONValueForURL:url]; }
which is part of the SantiappsHelper class that also contains:
+ (id)fetchJSONValueForURL:(NSURL *)url{
NSString *jsonString = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
id jsonValue = [jsonString JSONValue];
NSLog(@"This is the string presented:%@",jsonString);
[jsonString release];
return jsonValue; //this is the line where it crashes
}
The php page contains this code:
<?php
include_once("JSON.php");
$json = new Services_JSON();
$link = mysql_pconnect("localhost", "user", "pw") or die("Could not connect");
mysql_select_db("iglobe") or die("Could not select database");
$query = "SELECT * FROM tags";
$arr = array();
$rs = mysql_query("SELECT * FROM tags");
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
Echo $json->encode($arr);
?>
And returns this as a result:
[
{"tagID":null,"originudid":"269d4008ba6575b9ec51a7f3237e757c2bcd6bf6","destintyudid":"1","latitude":"37.3317","longitude":"-122.031","date":"2010-02-23 11:44:11"},
{"tagID":null,"originudid":"F6869FB45D456859679808908967967007646764","destintyudid":"","latitude":"37.3317","longitude":"-122.031","date":"2010-02-23 15:25:04"},
{"tagID":null,"originudid":"2031aafb778b3a27635ae38e4315f31bba956805","destintyudid":"","latitude":"15.4778","longitude":"-88.0068","date":"2010-06-09 11:17:27"},
{"tagID":null,"originudid":"adf03902c18974c9d29edf27da779afa66438a3b","destintyudid":"","latitude":"15.5017","longitude":"-88.0355","date":"2010-09-11 21:21:22"},
{"tagID":null,"originudid":"2031aafb778b3a27635ae38e4315f31bba956805","destintyudid":"","latitude":"15.4778","longitude":"-88.0068","date":"2010-06-09 11:18:45"}
]
but the app crashes with this error:
[__NSArrayM getObjects:andKeys:]: unrecognized selector sent to instance 0x6e579f0
I dont understand why its crashing. Its right before or when returning the jsonValue to the fetchInfoForUDID method that it crashes. Its returning the php-json created object to the fetchInfoForUDID method. This is a dictionary return value so why is the __NSarrayM getObjects:andKeys: being called?