0

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 &#8220 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);
};
Daan
  • 179
  • 1
  • 4
  • 14
  • Check if in the response header there the charset=utf-8'. Otherwise you can try to add this header in your PHP scripts:header('content-type: application/json; charset=utf-8'); – erlangb Jun 27 '14 at 15:40
  • Yes, headers: HTTP/1.1 200 OK Server: nginx Date: Fri, 27 Jun 2014 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; expires=Sat, 28-Jun-2014 15:42:12 GMT; path=/driveeatsleep/ X-Powered-By: PleskLin – Daan Jun 27 '14 at 15:43
  • Ok sorry, I've understand something different. Look here: http://stackoverflow.com/questions/17678694/avoid-special-characters-e-g-8217-when-parsing-an-xml-feed – erlangb Jun 27 '14 at 15:48

1 Answers1

0

I found a ugly but working solution.

In titanium I added a array with those special chars, and their equal normal chars to replace with.

Daan
  • 179
  • 1
  • 4
  • 14