I have data stored in mysql database, the data is encoded in ascii because of some special characters, i am trying to fetch data for iphone application, the json format is correct but due to special characters it returned me null 42756666616c6f205068696c6c79e28099732077696e67732c20636865657365737465616b7320616e64206d6f7265 this is stored in mysql table while actually it is Buffalo Philly’s wings, cheesesteaks and more i tried with html_entity_decode, html2text but none help me, please help on this i am really stucked.
here is the code how i fetch data from db and print it in json format:
$sql = "SELECT p.product_id,p.image,p.model,d.name,d.product_id,d.language_id FROM product AS p ,product_description AS d
WHERE
d.product_id = p.product_id
AND
d.language_id = 1
ORDER BY p.date_added
limit 10
";
$rs = mysql_query($sql);
$data = array();
$products = '{"products":{';
$num = mysql_num_rows($rs);
while($d = mysql_fetch_array($rs)){
$image = new SimpleImage();
$image->load($path.$d['image']);
$image->resize(55,55);
$img = strtotime("now").$count;
$image->save("images/".$img.'.jpg');
$pimage = "$img_url/$img.jpg";
$name = html_entity_decode($d['name'],ENT_QUOTES, 'UTF-8');
$highlight = html_entity_decode($d['model'],ENT_QUOTES, 'UTF-8');
if($count < $num){
$products .= '"'.$d["product_id"].'":[
{
"id":"'.$d["product_id"].'",
"name":"'.$name.'",
"image_url":"'.$pimage.'",
"highlight":"'.$highlight.'"
}
],';
}else{
$products .= '"'.$d["product_id"].'":[
{
"id":"'.$d["product_id"].'",
"name":"'.$d["name"].'",
"image_url":"'.$pimage.'",
"highlight":"'.$highlight.'"
}
]';
}
}
$products .='}}';
print($products);
Object-c code is:
NSData *data = [NSData dataWithContentsOfURL:soURL];
NSError *error;
productsRaw = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
products = [productsRaw objectForKey:@"products"];
productKeys = [products allKeys];