0
我有一個JSON api插件的Wordpress網站,它刪除了所有的帖子。鈦手柄HTML格式的JSON請求
在我的鈦合金項目中,我得到了JSON en解析它,把它放在tableview中。 。
但是,像「將被轉換爲&#8220和鈦將顯示它這樣的特殊字符如何在鈦解碼此
JSON獲取代碼:
var data = [];
var sendit = Ti.Network.createHTTPClient({
onerror : function(e) {
Ti.API.debug(e.error);
alert('There was an error during the connection');
},
timeout : 5000,
});
// Here you have to change it for your local ip
sendit.open('GET', 'http://development.webor.nl/driveeatsleep/api/get_posts/');
sendit.send();
// Function to be called upon a successful response
sendit.onload = function() {
var json = JSON.parse(this.responseText);
// var json = json.todo;
// if the database is empty show an alert
if (json.length == 0) {
$.hotelList.headerTitle = "The database row is empty";
}
// Emptying the data to refresh the view
// Insert the JSON data to the table view
var hotels = json.posts;
for (var i = 0, iLen = hotels.length; i < iLen; i++) {
if(hotels[i].excerpt.length >= 50){
var excerpt = hotels[i].excerpt.substring(50,0) + '...' ;
}else{
var excerpt = hotels[i].excerpt;
}
// Remove HTML tags and coding
excerpt = excerpt.replace(/<[^>]+>/g,'');
data.push(Alloy.createController('row', {
icon : hotels[i].thumbnail,
title : hotels[i].title,
description : excerpt
}).getView());
// data.push(row);
Ti.API.info(hotels[i].thumbnail);
Ti.API.info(hotels[i].title);
}
$.hotelList.setData(data);
};
檢查的RESP onse頭部有charset = utf-8'。否則,您可以嘗試在您的PHP腳本中添加此頭文件:header('content-type:application/json; charset = utf-8'); – erlangb
是的,頭文件:HTTP/1.1 200 OK 服務器:nginx 日期:2014年6月27日星期五15:42:13 GMT Content-Type:application/json; charset = utf-8 Content-Length:184747 Connection:close Expires:Thu,19 Nov 1981 08:52:00 GMT Cache-Control:no-store,no-cache,must-revalidate,post-check = 0,pre-check = 0 Pragma:no-cache X-Pingback:http://development.webor.nl/driveeatsleep/xmlrpc.php Set-Cookie:_icl_current_language = nl;到期=星期六,28-Jun-2014 15:42:12 GMT;路徑=/driveeatsleep/ X-Powered-By:PleskLin – Daan
好的,我明白不同的東西。看看這裏:http://stackoverflow.com/questions/17678694/avoid-special-characters-e-g-8217-when-parsing-an-xml-feed – erlangb