我有數據存儲在MySQL數據庫中,數據編碼爲ascii由於一些特殊字符,我試圖爲iphone應用程序獲取數據,json格式是正確的,但由於它返回的特殊字符我空 42756666616c6f205068696c6c79e28099732077696e67732c20636865657365737465616b7320616e64206d6f7265 這是存儲在MySQL表,而實際上它是布法羅費城的翅膀,奶酪牛排和更 我html_entity_decode,html2text但沒有試圖幫助我,請幫助這個我真的stucked。ASCII字符返回null NSJSONSerialization
這裏是我的代碼如何從數據庫中提取數據,並以JSON格式打印:
$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);
對象的C代碼:
NSData *data = [NSData dataWithContentsOfURL:soURL];
NSError *error;
productsRaw = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
products = [productsRaw objectForKey:@"products"];
productKeys = [products allKeys];
發佈您的代碼。你如何獲取數據? – Kreiri
@Kreiri我編輯了這個問題,用php代碼從數據庫獲取數據 – MIrfan
他的意思是objC代碼,我猜... –