The solution of andriod Chinese garbled problem

Source: Internet
Author: User

In the process of doing the project, often encounter garbled problem. In fact, you understand the cause of garbled characters, then you can quickly locate garbled problems.

So we have to locate the location of garbled characters, have some work experience, can quickly locate the problem of garbled, and can give a solution.



To locate garbled steps, in fact, there are two steps:

1. Garbled characters caused by the client

2. Garbled characters caused by server side


Only if you analyze these two critical points, I believe you can quickly locate the reason for your garbled appearance.


1. Client garbled location, first you want to determine the server side is no problem, then you can locate the client garbled.

Here, I assume that you have determined that the server is no garbled problem. You can go on. Locate the client for garbled reasons. Because the server side has been garbled problem, you post or get the content of the submission up is still garbled. Remember, the premise here is: the server has no garbled problem , encoding format you can ask the development server-side colleagues.


Let's locate the reason why the client is garbled:

The garbled location in your client appears to break the point in the code. I use eclipse here. After hitting the breakpoint debug, go to the line of code you want to view, watch the value, for example, I look at a variable is "content." If it is garbled, then you can be sure that is the client-generated garbled. When you are sure that the client is having problems, look at the place where the variable "content" is used. See if it is a garbled question before the assignment or after the assignment.


The client garbled solution:

1. Unified encoding format, if you are an Android client. If the IDE you are developing is eclipse, the best thing to do is set your project to UTF-8 (here's a suggestion: Start by setting your project environment to utf-8 every time you do a project). Of course, if you haven't set your coding format before, it's a bit trickier. If your eclipse is not set up at first, the default is GBK or ios8859-1. Generally to show normal words, only unified encoding method, will not appear garbled. If you want to display Chinese correctly, you need to set a specific encoding format: Common Chinese encoding format: UTF-8, GBK, GB2312 these kinds.

about how to set the encoding format in eclipse, specific Baidu.

2. If your code is not unified, then you are more tragic. For example, if you have not set up your project coding format before, then your project has been developed in half, and it is not supported in Chinese encoding format. such as iso8859-1, then you can only in the case of garbled to solve. That's why I suggested before (every time you do a project, you first set your project environment to Utf-8). Can worry a lot later.

New String (Content.getbytes (Charset.forname ("Current encoding format"), Charset.forname ("Target encoding Format"));

New String (Content.getbytes (Charset.forname ("iso8859-1")), Charset.forname ("UTF-8"));// Converts a iso8859-1 content string to a UTF-8 format

Above is to solve the problem of garbled string.

3. Garbled solution when network interaction occurs

Common ways we interact with the web are generally get or post.

In the client, we generally want to encode, and then the server that end in decode can solve the problem of Chinese garbled. Negotiate with the server development side, those fields need to be decode.

Uri.encode ()



2. Service side garbled location, the first best is to determine the server side has no garbled problem

The general server-side garbled problem is relatively easy to determine, for example, I am doing andriod client development. So when interacting with the network, it is generally provided to our interface. Then we directly use interface to determine the interface to submit Chinese is there any problem? If there is a problem, consult with the server developer in time. Identify problems with garbled characters. Generally experienced server-side development will give you advice soon, and tell you the front-end to use Uri.encode, and then he decode on the server side. This way the service side of the garbled problem is solved. Then you in the overall test, see if the client will be garbled problem, if there is a problem, then skip to the client garbled location.


The solution of andriod Chinese garbled problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.