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