我要生成的JSON值正是像這樣一個在這裏生成JSON不使用PHP和MySQL
{
"feed": [
{
"id": 1,
"name": "National Geographic Channel",
"image": "http://api.androidhive.info/feed/img/cosmos.jpg",
"status": "\"Science is a beautiful and emotional human endeavor,\" says Brannon Braga, executive producer and director. \"And Cosmos is all about making science an experience.\"",
"profilePic": "http://api.androidhive.info/feed/img/nat.jpg",
"timeStamp": "1403375851930",
"url": null
},
{
"id": 2,
"name": "TIME",
"image": "http://api.androidhive.info/feed/img/time_best.jpg",
"status": "30 years of Cirque du Soleil's best photos",
"profilePic": "http://api.androidhive.info/feed/img/time.png",
"timeStamp": "1403375851930",
"url": "http://ti.me/1qW8MLB"
}
]
}
每次我嘗試做這樣的事我結束了這個輸出時間斜線
{
"feed": [{
"id": "1",
"name": "National Geographic Channel",
"image": "http:\/\/api.androidhive.info\/feed\/img\/cosmos.jpg",
"status": "Science is a beautiful and emotional human endeavor",
"profilePic": "http:\/\/api.androidhive.info\/feed\/img\/nat.jpg",
"timeStamp": "1403375851930",
"url": "null"
}, {
"id": "2",
"name": "National Geographic Channel",
"image": "http:\/\/api.androidhive.info\/feed\/img\/cosmos.jpg",
"status": "Science is a beautiful and emotional human endeavor",
"profilePic": "http:\/\/api.androidhive.info\/feed\/img\/nat.jpg",
"timeStamp": "1403375851930",
"url": "null"
}]
}
看看第一JSON的ID和網址 我希望我的JSON是完全一樣的第一個
我的PHP代碼:
<meta http-equiv="Content-Type" content="application/json; charset=utf-8 ">
<?php
include "../funcs/db.php";
$SelectPosts = mysql_query("SELECT * FROM usf_mobile");
$rows = array();
while($r = mysql_fetch_assoc($SelectPosts)) {
$rows['feed'][] = $r;
}
print json_encode($rows);
?>
我試圖解決方案的很多在這裏計算器,我沒有找到任何一個誰可以接近我的問題。
將類型轉換爲int類型的id值賦給$ id =(int)$ id; – 2014-09-22 18:36:43
首先爲什麼它應該是這樣的**完全**? – 2014-09-22 18:37:26
你需要看看爲編碼http://php.net/manual/en/json.constants.php添加選項,至少將幫助使用JSON_UNESCAPED_SLASHES – 2014-09-22 18:38:29