I have a JSON api plugin for a Wordpress site, which trows out all the posts.
In my Titanium Alloy project I'am getting the JSON en parse it, to put it in a tableview.
But the special chars like " will be converted to “ and Titanium will show it like this. How do I decode this in 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);
};