在此处输入图像描述我的 RetriveData.Php:
<?php
ini_set("display_errors","on");
include("connection.php");
$query= "SELECT * FROM Person" ; //replace with your table name
$result = mysqli_query($con,$query) or die("Error".mysqli_error($con));
//create an array
$json = array();
if(mysqli_num_rows($result))
{
while($row=mysqli_fetch_row($result))
{
$json[]=$row;
}
}
echo json_encode($json);
?>
这里是我的 .m 文件代码:
NSError *error = nil;
NSString *url_string = [NSString stringWithFormat: @"http://127.0.0.1/RetriveData.php"];
NSData *data = [url_string dataUsingEncoding:NSUTF8StringEncoding];
NSMutableArray *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSLog(@"%@",error);
NSLog(@"json: %@", json);
问题是这个 json 数组打印 Null。