0
我想从我的MYSQL数据库中读取一行并将其变成我的应用程序中的一个字符串数组。从MySQL数据库导入iOS应用程序中的数据
我的PHP文件:
<?php
$host = 'localhost';
$user = 'root';
$password = '';
$database = 'diplomarbeit_testdatenbank';
$db_link = mysqli_connect($host, $user, $password, $database);
$sql = "SELECT Kategorie FROM Kategorien WHERE Anzeige = '1'";
$result = mysqli_query($db_link, $sql);
$records = array();
$array = array();
while($row = mysqli_fetch_assoc($result)){
$records['Kategorie'] = $row['Kategorie'];
array_push($array, $records);
}
echo json_encode($array);
?>
...给我,输出:
[{ “Kategorie”: “外部对象”},{ “Kategorie”: “家”}, { “Kategorie”: “莱勒”},{ “Kategorie”: “Oeffnungszeiten”},{ “Kategorie”: “Orientierung”},{ “Kategorie”: “Schulleitung”}]
中的功能我应用程序(使用Xcode 8和Swift 3):
func get()
{
do{
let dburl = URL(string: "http://127.0.0.1/index.php")
let dbdata = try Data(contentsOf: dburl!)
let json = try JSONSerialization.jsonObject(with: dbdata, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String:AnyObject]
if let arrJSON = json["Kategorie"]
{
for indexx in 0...arrJSON.count-1
{
let aObject = arrJSON[indexx]
TableArray.append(aObject as! String)
}
}
}
catch let error as NSError{
print("Failed to load: \(error.localizedDescription)")
}
}
它不显示任何错误或类似的东西。当我模拟它时,应用程序冻结在我尝试序列化的那一行。
而显而易见的问题是:这里出了什么问题?