2013-07-25 84 views
-1

因此,這是來查看我的JSON文件:http://alyssayango.x10.mx/JSON URL字段中顯示不正確

這是我的PHP文件:

<?php 
include('connectdb.php'); 
$sql = "SELECT * FROM tblmovies ORDER BY _id"; 
$result = mysql_query($sql);  
if($result === FALSE) { 
die(mysql_error()); // TODO: better error handling 
} 
$set = array(); 
while($row1 = mysql_fetch_assoc($result)) { 
    $set[] = $row1; 
} 
echo json_encode($set); 

,輸出是:

[{"_id":"3","movie_name":"Despicable Me 2","movie_cinema_number":"CINEMA  1","movie_length":"1hr. 40mins.","movie_type":"GP","movie_schedules":"12:10 PM | 02:25 PM | 04:40 PM","movie_image_url":"http:\/\/i39.tinypic.com\/szizo4.jpg"},{"_id":"4","movie_name":"White House Down","movie_cinema_number":"CINEMA 2","movie_length":"2 hrs. 10 mins.","movie_type":"PG-13","movie_schedules":"12:30 PM | 03:20 PM | 06:10 PM","movie_image_url":"http:\/\/i39.tinypic.com\/vp9n9j.jpg"},{"_id":"5","movie_name":"My Lady Boss","movie_cinema_number":"CINEMA 3","movie_length":"1hr. 50 mins.","movie_type":"PG-13","movie_schedules":"01:00 PM | 03:30 PM | 06:00 PM","movie_image_url":"http:\/\/i44.tinypic.com\/2qlv08z.jpg"},{"_id":"6","movie_name":"Four Sisters And A Wedding","movie_cinema_number":"CINEMA 4","movie_length":"2 hrs. 5 mins. ","movie_type":"PG-13","movie_schedules":"12:30 PM | 03:10 PM | 05:50 PM","movie_image_url":"http:\/\/i44.tinypic.com\/9iv0d1.jpg"}] 

我在這裏做什麼似乎是錯誤的? URL顯示爲:http:\/\/i44.tinypic.com \ /9iv0d1.jpg它應該是http://i44.tinypic.com/9iv0d1.jpg

+0

Arent這兩個網址你張貼...相同? –

+0

你的意思是json_encode越獄的事實? – DevZer0

+0

@ DevZer0是的,我認爲是這樣的 –

回答

3

JSON格式通常用於通過網絡連接序列化和傳輸結構化數據。它主要用於在服務器和Web應用程序之間傳輸數據,用作XML的替代品。

如果您創建一個API應該是:

$array = array("title" => "TEST", "username" => "test"); // Creating a array 
echo json_encode($array); // Printing json 

客戶要申請並得到迴應:

$json = file_get_contents('http://www.example.com/test/films.json'); // Your url 
$array = json_decode($json); // Your first array its here! 

更多:http://en.wikipedia.org/wiki/JSON
警告:你不能編輯或ti dy你的json響應!這很好!

0

實際上,問題不存在。

你做錯了什麼是你使用了一塊JSON字符串,而沒有事先解碼它。只要使用json_decode(..)即可,如果您使用PHP或相應的JavaScript函數來解碼JSON。

一旦你這樣做了,你將有一個對象/一個數組,其中包含正確的形式的數據。

+0

那麼我在哪裏使用我的代碼中的解碼? –

+0

@neknekmouh無論哪個腳本正在監聽回顯的字符串。我不知道你要發送這個JSON,我怎麼回答你? –

+0

其實,我會懶惰加載到我的列表視圖在Android應用程序 –