in mysql db table
varchar title(20) - db table column.
title: Banana™ - table row.
in return.php (server)
$get_query=$_GET['query'];
$connect=mysql_connect("localhost","root","") or die("die");
mysql_select_db("testdb",$connect);
$query=mysql_query($get_query,$connect);
while($row = mysql_fetch_array($query ))
{
$list[]=$row;
}
print json_encode($list);
mysql_free_result($query);
mysql_close($connect);
in ios (client)
NSString * szURL =[NSString stringWithFormat:@"http://localhost/return.php?query=%@",query];
NSURL *url = [NSURL URLWithString:[szURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ]];
NSString *strData = [NSString stringWithContentsOfURL:url
encoding:NSUTF8StringEncoding
error:&error];
NSDictionary *rootItem = (NSDictionary *)[strData JSONValue];
NSArray * appLists= (NSArray *)rootItem;
NSMutableArray *resultArray =[[[NSMutableArray alloc]init] autorelease];
for(NSDictionary * oneApp in appLists)
{
NSString *appTitle=(NSString*)[oneApp objectForKey:@"title"];
}
but appTitle is NULL;
I think , I need to covert character.
™ is problem.
How I get Banana™ by (NSString *)??
Maybe the problem is here:
Is it an Array or a Dictionary? Check this out before iterate over
appLists. ANSLogto[strData JSONValue];can be really useful.