2

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

Shyam
  • 6,376
  • 1
  • 24
  • 38
Jeetu
  • 686
  • 2
  • 10
  • 20

3 Answers3

7

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();
}
General Grievance
  • 4,555
  • 31
  • 31
  • 45
CRUSADER
  • 5,486
  • 3
  • 28
  • 64
1

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.

No_Rulz
  • 2,679
  • 1
  • 20
  • 33
  • and also refer http://androidcodemonkey.blogspot.in/2010/03/how-to-base64-encode-decode-android.html – No_Rulz Jul 03 '13 at 13:01
  • i m using base 64 class also but it show rectangle at place of String tv1.setTag(Base64.decode(str.getBytes())); – Jeetu Jul 03 '13 at 13:12
-2

K Thanks friends for reply all ur given code works on Real device but it doesn't work on emulator

we don't have to display text on real device just set text in your textview and it works fine.

tv1.setText(str);

Sikander
  • 447
  • 4
  • 26
Jeetu
  • 686
  • 2
  • 10
  • 20