Reputation: 21760
In php I have:
$result = mysql_query($query);
// if successful query, return the records
if ($result)
{
// if not empty result, return array of records
if (mysql_num_rows($result))
{
$records = array();
while ($row = mysql_fetch_assoc($result))
{
$records[] = $row;
}
return $records;
}
}
In Objective-C - After the POST I have the following code...
NSURLResponse *newStr = [[NSURLResponse alloc] init];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&newStr error:nil];
returnData is equal to the literal "Array", not the contents of $records[]
Upvotes: 1
Views: 1988
Reputation: 95355
You should serialise the data into a XML type plist
format if you can, then it can be natively interpreted by Cocoa classes like NSArray and NSDictionary. NSPropertyListSerializer is capable of producing mutable or immutable arrays and dictionaries from a file or from an NSData object containing serialized data in plist format.
NSDictionary can also read files in this format:
"key" = "value";
"key2" = "value2";
Likewise, NSArray can read files in this format:
(
"value1",
"value2",
"value3",
"30",
"value5"
);
In fact, I think if the strings don't contain spaces, the quotes are optional (but I guess they would force string types).
Check out this URL for more information about oldschool ASCII property lists. They are read-only, but then again they are easy enough to generate manually or systematically.
Upvotes: 1
Reputation: 10722
You need to format your array in some format that you can read in Objective-C. I recommend using JSON.
If you have PHP 5.2, you can use the built in functions to encode your data. For example:
echo json_encode($records);
On the Objective-C side, you can use TouchJSON to decode/encode JSON.
Upvotes: 2
Reputation: 32336
On the PHP side you need to serialize the array to a format like JSON or XML rather than just print
ing it. On the iPhone side would then deserialize the NSData
object using the appropriate library
Upvotes: 0