Tapan
Tapan

Reputation: 187

Character Encoding during REST GET API Call

I have a json data

{

  "description": "Architectures of Adobe\ufffds AEM Forms and LiveCycle ES4 systems. IT architects who are considering Adobe\ufffds AEM Forms and LiveCycle ES4 so\ufffdftware for their enterprise\ufffds form and document systems.",

  "title" : "This course includes an introduction to the Creative Cloud and services such as Libraries, Adobe Stock, Typekit, Mobile Apps, and Bēhance."
}

Java code to get this data is-

    HttpClient httpClient = new HttpClient();
    HttpMethod method = new GetMethod(url);
    method.addRequestHeader("accept", "application/json");
    method.addRequestHeader("X-API-Key", apiKey);
    method.addRequestHeader("certificate", certificate);
    int status = httpClient.executeMethod(method);
    JSONObject data = (JSONObject) JSONValue.parse(method.getResponseBodyAsString());
    String desc = data.get("description").toString();
    String data = data.get("title").toString();

However I get the results as-

desc - Architectures of Adobe�s AEM Forms and LiveCycle ES4 systems. IT architects who are considering Adobe�s AEM Forms and LiveCycle ES4 so�ftware for their enterprise�s form and document systems.

data - This course includes an introduction to the Creative Cloud and services such as Libraries, Adobe Stock, Typekit, Mobile Apps, and BÄhance

Seems to be an encoding issue..Any idea how to fix this....Thanks

Upvotes: 3

Views: 22462

Answers (1)

Ram
Ram

Reputation: 748

Please try to include Accept-Charset in the request header... Hopefully the server honors this and sends the appropriate charset as a part of Content-Type response header.. this RFC 2616 states that Accept-Charset should be honored by the server

Possible values for Accept-Charset include but are not limited to...

utf-8

iso-8859-1

refer - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Charset

Upvotes: 1

Related Questions