好吧,我应该更好地解释这个问题。我开发了一个iPhone应用程序来显示数据。数据是使用php文件从Mysql数据库中获取的。JSON编码问题ios 5
在这里,我告诉PHP文件的代码:
<?php
header("text/html; charset=utf-8");
//Credenciales de la BBDD
$db = "json";
$host = 'localhost';
$username = "dpbataller";
$password = '1234';
//Conectamos al servidor de la Base de datos
$link = mysql_connect($host,$username,$password) or die("No se puede conectar");
//Seleccionamos la BBDD
mysql_select_db($db) or die ("No se ha podido seleccionar a la base de datos");
mysql_set_charset('utf8', $link);
//Lanzamos la consulta
$consulta = mysql_query("SELECT id,nombre from personas");
//Creamos un array para almacenar los resultados
$filas = array();
//Agregamos las filas devueltas al array
while ($r = mysql_fetch_assoc($consulta)) {
$filas[] = $r;
}
//Devolvemos el resultado
echo json_encode($filas);
?>
在这一刻,如果我上运行的浏览器的脚本,他返回 [{ “ID”: “0”, “农布雷”: “佩普\ u00e9”}]
此外,在Xcode项目我写了这个代码:
NSString *urlString = [NSString stringWithFormat:@"http://10.0.1.18/mysql_iphone/mostrar_personas.php"];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"%@", json);
和控制台,返回: ( { id = 0; nombre =“Pep \ U00e9”; } ) 像浏览器...这是我的问题,因为我有口音的人noums ...
你缺少您告诉我们您所遇到的问题的一部分。 – rckoenes
这可能对于某些人来说是显而易见的,你都搞不清出现编码的Unicode字符,但我@rckoenes同意...请花一些时间来好好解释一下你的问题......我 – Alladinian
改写了这个问题,抱歉 – dpbataller