I currently retrieve information from my database with JSON by doing this in my php file, let's call it getJson.php:
<?php
include ("config.php");
$query = "SELECT id,title,text,image,date FROM posts";
$result = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);
$rows = array();
while ($r = mysql_fetch_assoc($result)){
$rows[] = $r;
}
echo json_encode($rows);
?>
Then in my application I retrieve the JSON representation by using:
NSURL *url = [NSURL URLWithString:kGETUrlPosts];
NSData *data = [NSData dataWithContentsOfURL:url];
NSError *error;
postsArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
I also have binary image data stored as a BLOB which I would like to retrieve. However I cannot JSON encode this binary data in JSON, can I ?
My second option would have been keeping a URL to my image in the image field and then just call
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"www.myURL.com/MyPhotos/somephoto.png"]]];