Socialcast Rest Api服务的UTF-8输出

时间:2013-12-29 11:45:19

标签: java rest curl utf-8 apache-httpclient-4.x

我正在使用带有CURL的Socialcast rest api。这是我的curl命令,

`curl -k -X GET -v --basic -u "email:password" https://<dpmain>.socialcast.com/api/messages/18755210.json`

上述命令的输出为,

{"message":{"id":18755210,"user":{"id":964633,"name":"username","url":"myrepo","username":"myname","active":true,"te
rminated":false,"inactive":false,"role":"member","type":"User","title":"SE","out_of_office":false,"back_in_office_on":null,"company_login":null},"title":"","body":"\"\u
0db8\u0dad\u0dca \u0d9a\u0dd4\u0da9\u0dd4 \u0d9a\u0db1\u0dca\u0da7\u0dda\u0db1\u0dbb\u0dba \u0dc3\u0db8\u0dca\u0db6\u0db1\u0dca\u0db0 \u0dc3\u0dd2\u0daf\u0dca\u0db0\u0d
d2\u0dba\u0dda\u0daf\u0dd3 \u0d85\u0d9c\u0db8\u0dd0\u0dad\u0dd2\u0dc0\u0dba\u0dcf\u0d9c\u0dda \u0dbb\u0dd9\u0daf\u0dca\u0daf \u0d9a\u0dd0\u0d9e\u0dd3 \u0db1\u0dd2\u0dbb
\u0dd4\u0dc0\u0dad \u0db4\u0dda\u0db1\u0dca\u0db1\u0dda \u0da2\u0dcf\u0dad\u0dd2\u0d9a \u0dc4\u0dd9\u0dc5 \"","action":"","verb":null,"message_type":"status_message","i
con":null,
"external_url":"","created_at":"2013-12-14T14:43:01+00:00","updated_at":"2013-12-14T14:43:01+00:00","likes":[],"likes_count":0,"comments":[],"comments_count":0,"attachm
ents":[],"media_files":[],"contains_url_only":true,"external_resources":[],"tags":[],"last_interacted_at":1387032181,"group":{},"category_id":null,"recipients":[],"thum
bnail_url":null,"player_url":null,"player_params":null,"likable":false,"ratable":false,"rating":null,"ratings_average":null,"ratings_count":null,"editable":true,"deleta
ble":true,"watchable":false,"watch":null,"flag":null,"source":{"name":"web","formal_name":"Web App","id":"web"},"poll":null,"embed":null,"hidden":null,"subscribed":null
,"groups":[],"extensions":[],"new_group_id":null,"new_group_archived_at":null,"days_of_stickiness":0,"sticky_for_current_user":false}}* Connection #0 to host left intact

正如您所看到的,我收到了像\ u0da7 \ u0dda \ u0db1 \ u0dbb这样的字符作为回应。他们是UTF-8字符吗?如何使用Java获得可读的字符集? 实际上我应该得到以下可读字符(那些是用sinhala语言), “මත්කුඩුකන්ටේනරයසම්බන්ධසිද්ධියේදීඅගමැතිවයාගේරෙද්දනිරුවතපේන්නේජාතිකහෙළහෙළ”

无论如何我使用Windows命令提示符来执行curl命令。我也尝试通过在请求中指定内容类型标题,但结果相同。 “Content-Type”,“application / json; charset = UTF-8”

我也尝试使用简单的java程序(apache http客户端)和eclipse,并通过写入文件获得相同的结果。

让我知道如何从上面获取可读字符。

注意: 如果我使用chrome高级休息客户端执行此休息服务,我可以获得可读字符。但是高级休息客户端中的原始输出具有相同的不可读字符。

此致 -Lasith。

1 个答案:

答案 0 :(得分:0)

您需要将这些转换为代码中的可读字符串。您可以使用以下内容:

String unicode = "\u0db8\u0dad\u0dca \u0d9a\u0dd4\u0da9\u0dd4";
String string = new String(unicode.getBytes("UTF-8"), "UTF-8");
System.out.println(string);