Q:

Convert euro sign from a PHP sent JSON string to a Java string (utf-8)

i am building an Android application that prints to a thermal printer and i have problems with printing &euro; symbol.
Specifically, my Android application:

makes a GET request  to a php file
the php file build a JSON object
one of my JSON values contains a "\u20AC", that is, euro sign in unicode.
php file stringifies the JSON + send it back to Android

which sends the data UTF-8 encoded (plain text)
My PHP sending-back code is, basically, something like that:
header("Content-Type: text/html; charset=UTF-8\n");
...
$currency_symbol = '\u20AC';
...
$blah = array("id"=>$order['id'], ... , "currency_symbol"=> $currency_symbol);
echo json_encode( $blah ); 
exit;

Before all that, i was able to print the € sign to a printer by:

Changing to correct code page of thermal printer
Calling the following code:

new String("\u20ac").getBytes( Charset.forName("Windows-1252") ) );
then sending euro bytes directly to printer.
With JSON solution, i can not render the euro sign anymore as every try, even the previous working one, it always renders this to printer (but not the sign):
\u20AC
PS. I have no problem with the other UTF-8 strings as i am able to print them by that:
String.format("- " + json_obj.getString("address") + "\n").getBytes( charset )

where json_obj is the encoded JSON that came from PHP and charset in what code page the printer is set to (as Charset).

A:

I solved it by using the following code:
String currency_symbol_hex = order_obj.getString("currency_symbol");
String currency_symbol_str = Character.toString((char) Integer.parseInt(currency_symbol_hex,16));
BT_write( String.format("%s", currency_symbol_str).getBytes( Charset.forName("Windows-1252") ) );

where order_obj.getString("currency_symbol") is a JSON value sent by the PHP and contains only 20AC (rather \u20AC) and BT_write basically writes the bytes to a connected Bluetooth socket.
The currency_symbol is stored in JSON like that:
   return array(
      ...
      "euro"=>array("symbol"=>"&euro;","symbol_unicode"=>"20AC")
                                                   -------^
      ...
   );

and i just return it through the currency_symbol key in my JSON.
This is obviously not the best solution as different currencies may require different character set than Windows-1252 and also requires special case on PHP side (sending 2 unicode codes eg. \u0631.\u0639. (the Omani rial currency symbol) wont work unless you use an array and parse each one etc.) but at least its a start. Thanx!

