0

I need to make a search but my dada are encoded (in JSON OBJECT) like this: Coordenação and when i type "Coordenação" on input I didn't find nothing.

I want to know if have any function to convert Coordenação to Coordenação

I'm not sure but I think "Coordenação" is UTF-8 encoding and other string is ISO-8859-1

I get the correct string from my oracle database, and it shows correctly in browser, but when i see my code source with my browser, i see my json object with these characters (I'm making a json object with data from database).

I'm searching for hours how to fix this with other solution but without success, now I'm trying to do convert the data typed on input to match with json data.

Joao Paulo
  • 1,083
  • 4
  • 17
  • 36
  • 1
    http://stackoverflow.com/editing-help#code – SLaks Dec 05 '13 at 16:24
  • 1
    Don't do that. JSON objects should not have XML entities. – SLaks Dec 05 '13 at 16:25
  • 1
    where is your data coming from that it looks like that? It feels like there's a missing step when that data is loaded to JSON object. As for the encoding, one is "actual text" encoding, the other is "we don't know which encoding you're using, so we're giving you unicode, with all the non-ascii characters as character entity strings" – Mike 'Pomax' Kamermans Dec 05 '13 at 16:26
  • Use Notepad++ to see what happens to the strings. In that program you can change the encondings at will.} – Carlos487 Dec 05 '13 at 16:28
  • 1
    http://stackoverflow.com/questions/1354064/how-to-convert-characters-to-html-entities-using-plain-javascript – Jonathan Dec 05 '13 at 16:31
  • Storing strings with HTML/XML entities in JSON is going about things the wrong way. Those are, in general, only for I/O, not storage - unless your storage format happens to be XML, which JSON isn't. – Mark Reed Dec 05 '13 at 16:33
  • I'm using json only beacause Dynatree component requires this. – Joao Paulo Dec 05 '13 at 16:35

1 Answers1

1

Thank You @Jonathan. I found the solution in your link.

This function do exact what I want:

    function encodeHTML(str) {
        var aStr = str.split(''),
            i = aStr.length,
            aRet = [];

        while (--i) {
            var iC = aStr[i].charCodeAt();
            if (iC < 65 || iC > 127 || (iC > 90 && iC < 97)) {
                aRet.push('&#' + iC + ';');
            } else {
                aRet.push(aStr[i]);
            }
        }
        return aRet.reverse().join('');
    }
Joao Paulo
  • 1,083
  • 4
  • 17
  • 36
  • 1
    As a Brazilian, I've been through this kind of problem too. That's a good source to have a read: http://www.javascripter.net/faq/accentedcharacters.htm – emerson.marini Dec 05 '13 at 16:41