3

I have this on my JSON-file (mydata.json on the server):

    "jp": [ "私はあなたを愛しています!", 

and more. There is also "de" and "en" and so on and it is displayed correctly. But with these japanese characters, I get these unrecognizable characters. I have read threads here but I can't find a solution. I think it has something to do with the data from the server, wrong asking header, but don't know, how to fix it. I tried this (found here on stackoverflow) (file.js):

    $.ajax({url: myURL, contentType: "application/json; charset=utf-8",
    success: function(dataJSON){        
        console.log(dataJSON); 
            }
    });

End the outputs of the "de" and "en" (and more) are great, but the japanese characters appear like this:

���͂��Ȃ��������Ă��܂��I 

How can I fix it?

4
  • What kind of header does your server side part of the AJAX call have? Commented May 22, 2014 at 9:19
  • From where u fetch these data? if from Db, how it is stored in Db. Commented May 22, 2014 at 9:20
  • In java side :String str = "私はあなたを愛しています!"; str = new String(str.getBytes("8859_1"), "UTF-8"); Commented May 22, 2014 at 9:23
  • Ah thank you! When I wrote the mydata.json on my server I had to change the coding of the file to Shift-JIS, because there only show me cryptical instead of japanese characters. Now I have changed it (I thought they will disappear, but they don't) to UTF-8 and now it works. Strange. Commented May 22, 2014 at 9:42

3 Answers 3

1

In the server you need unicode http://unicode-table.com/en/#cjk-radicals-supplement In javascript there is no problem because it uses unicode

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Yes I changed the coding and now it works. Interesting site by the way.
0

set Content-Type: text/html; charset=utf-8 at the beginning of the the file you request json from it

Comments

0

Try this! Ajax automatically detects the dataType, but here it is explicit.

$.ajax({
    url: myURL, 
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(dataJSON){        
       console.log(dataJSON); 
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.