我想用json_encode將模型查詢轉換爲json,但它不起作用。但是它有一個普通的陣列。將codeigniter查詢轉換爲json?
$arr = array("one", "two", "three");
$data["json"] = json_encode($arr);
輸出
<?php echo "var arr=".$json.";"; ?>
var arr=["one","two","three"];
但是,當我嘗試轉換查詢笨拋出一個錯誤。那是什麼? 這是錯誤消息:
甲PHP錯誤遇到嚴重性: 警告信息:[JSON] (php_json_encode)類型不受支持, 編碼爲空
並將轉換後的「查詢「結果=我的意思是模型的方法是這樣的:
{"conn_id":null,"result_id":null,"result_array":[],"result_object":[],"current_row":0,"num_rows":9,"row_data":null}
我嘗試做這樣的
$posts = $this->Posts_model->SelectAll();
$data["posts"] = json_encode($posts);
順便說一句,當我做沒有json_encode的模型和方法工作得很好。
東西我可以做的錯,但問題是什麼?
你能後不工作的代碼?我不明白你爲什麼要把你的查詢轉換成json。你不應該將結果數據轉換成json嗎? –
如果出現錯誤,您可能希望與我們分享錯誤。 ;-) –
你可以請發佈錯誤信息? – Pedro