0
我有這個PHP腳本,給了我一個JSON響應。有問題的網址查詢
<?php
include("init.php");
$string="";
$newString="";
$get_posts = "select * from books_table";
$run_posts = mysqli_query($con,$get_posts);
$posts_array = array();
while ($posts_row = mysqli_fetch_array($run_posts)){
$row_array['title'] = $posts_row['title'];
$row_array['author'] = $posts_row['author'];
$row_array['bookUrl'] = $posts_row['bookUrl'];
$row_array['imageUrl'] = $posts_row['imageUrl'];
$row_array['displayDate'] = $posts_row['displayDate'];
$row_array['numberOfPages'] = $posts_row['numberOfPages'];
array_push($posts_array,$row_array);
}
$string = json_encode($posts_array,JSON_UNESCAPED_UNICODE);
echo $string;?>
並且json我得到
[{"title":"Clean Code","author":"Robert Martin","bookUrl":"http:\/\/amzn.to\/1DJybxH","imageUrl":"http:\/\/adavis.github.io\/adept-android\/images\/clean_code.jpg\"","displayDate":"August 11, 2008","numberOfPages":"464"},{"title":"Effective Java","author":"Joshua Bloch","bookUrl":"http:\/\/amzn.to\/1Ku8Xel","imageUrl":"http:\/\/adavis.github.io\/adept-android\/images\/effective_java.jpg","displayDate":"May 28, 2008","numberOfPages":"346"},{"title":"Working Effectively with Legacy Code","author":"Michael Feathers","bookUrl":"http:\/\/amzn.to\/1Jqe1PA","imageUrl":"http:\/\/adavis.github.io\/adept-android\/images\/legacy_code.jpg","displayDate":"October 2, 2004","numberOfPages":"456"},{"title":"Refactoring: Improving the Design of Existing Code","author":"Martin Fowler","bookUrl":"http:\/\/amzn.to\/1Lx4cjR","imageUrl":"http:\/\/adavis.github.io\/adept-android\/images\/refactoring.jpg","displayDate":"July 8, 1999","numberOfPages":"464"}]
我想執行一個查詢,將返回其標題中包含乾淨的字的對象。
所以我用這個網址
[http://www.theo-android.co.uk/books/sample_data.php/q=clean][1]
Hoewever,我得到同樣的JSON響應前。該對象或對象不會被過濾掉。這是爲什麼發生?
謝謝,
泰奧。
哇。感謝您的幫助:)你是一個聰明的狗。 – Theo
我的榮幸:-) –
還有另外一個問題。如果你想使用一個url來獲得你的id對象並將其數據顯示爲一個json對象,該怎麼辦?即http://www.theo-android.co.uk/books/sample_data.php?id=1。謝謝 – Theo