0
我想在PHP中创建一个对象数组,然后在Swift中使用回声。当我在JSON对象上做println
时,我可以得到一个在Swift中显示的对象,但我需要回显很多对象。回声PHP阵列的对象Swift NSDictionary
class catRow{
public $id;
public $person;
public $item;
public $descr;
public $link;
public $price;
}
$prepare_string = "SELECT * FROM items ORDER BY person LIMIT 5";
$stmt = $dbh->prepare($prepare_string);
$stmt->execute();
while($row = $stmt->fetch()){
$catRow = new stdClass;
$catRow-> id = $row['id'];
$catRow-> person = $row['person'];
$catRow-> item = $row['item'];
$catRow-> descr = $row['descr'];
$catRow-> link = $row['link'];
$catRow-> price = $row['price'];
$allRows[] = $catRow;
}
echo json_encode($allRows);
,然后雨燕侧我已经(总结):
let catalogueRows: NSDIctionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary
println(catalogueRows)
这时候我赞同$catRow
但我想呼应从表中的每一行中我的数据库中运行。
什么println(catalogueRows)打印? – Jageen 2014-12-11 05:49:15
'fetch'函数返回一个布尔值,所以我不认为你的'while'循环是正确的。我会调用'bind_result'来将这些结果绑定到变量,然后在定义'catRow'时使用这些结果。或者,也可以使用'get_result'(如果只使用MySQL本地驱动程序),然后使用'fetch_assoc'或'fetch_array'来检索'$ row'变量的数据。 – Rob 2014-12-11 06:27:12