【发布时间】:2018-02-20 20:20:35
【问题描述】:
enter image description herehere 我的 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。
【问题讨论】:
-
你的问题是什么?
-
null 在 json 数组中返回。但使用相同的 url 我可以在浏览器上看到 json 数据
-
您的 WS 返回的响应不是 JSON 有效的(我们在屏幕截图中看到的那个)。您可以在在线 JSON 验证器上对其进行测试,您会看到。这就是您出现此错误的原因。
标签: php ios objective-c json jsonparser