钛合金处理HTML表单JSON请求


Titanium handle HTML form JSON request

我有一个Wordpress网站的JSON api插件,它可以显示所有的帖子。

在我的钛合金项目,我得到JSON解析它,把它放在一个表视图。

但是像"这样的特殊字符将被转换为“, Titanium将像这样显示它。我如何在Titanium中解码这个?

JSON get code:

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);
};

我找到了一个丑陋但有效的解决方案。

在titanium中,我添加了一个包含这些特殊字符的数组,并将它们的相等的正常字符替换为