Convert utf-8 encode in to a String in android
Solution 1
From ref from here . You only need new String(bytes, charset) and String.getBytes(charset)..
Try following code
String data = "\u092a\u093e\u0932\u094d\u092a\u093e\u0915\u093e \u092c\u0928\u094d\u0926\u0940\u0939\u0930\u0942 \u0915\u093e\u0930\u093e\u0917\u093e\u0930\u092d\u093f\u0924\u094d\u0930\u0948 \u0905\u0938\u0941\u0930\u0915";
byte[] bute = null;
bute = data.getBytes();
try {
String asd= new String(bute, "UTF-8");
System.out.println(asd);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I am sure it will print the data you want...
Hope this helps..
Solution 2
the problem is that you are converting your encrypted data to a String. encrypted data is binary, not String data. UTF-8 is a charset with a specific encoding format. arbitrary binary data is not valid UTF-8 data. when you convert the encrypted data into a String, the "invalid" characters are most likely getting replaced with the ? invalid char.
If you want to convert arbitrary binary data (aka encrypted data) into a String, you need to use some binary->text
conversion like Base64
.
Jeetu
Updated on July 23, 2022Comments
-
Jeetu over 1 year
i have json value Like
\u092a\u093e\u0932\u094d\u092a\u093e\u0915\u093e \u092c\u0928\u094d\u0926\u0940\u0939\u0930\u0942 \u0915\u093e\u0930\u093e\u0917\u093e\u0930\u092d\u093f\u0924\u094d\u0930\u0948 \u0905\u0938\u0941\u0930\u0915
How we get String or how to decode it in android and display it on text view.
i m perform some opration on it but it show log
??????????????????????????????
can some one help Me. Thanks
-
Jeetu over 10 yearsThanks for reply i try this
-
No_Rulz over 10 yearsand also refer androidcodemonkey.blogspot.in/2010/03/…
-
Jeetu over 10 yearsi m using base 64 class also but it show rectangle at place of String tv1.setTag(Base64.decode(str.getBytes()));