简体   繁体   中英

Delphi 7 - Charset REST JSON

With Delphi 7 and Indy 9.00.10 I'm using a REST API with JSON. I create a GET request with the TidHTTP component like this.

IdHTTP1.HandleRedirects := True;
IdHTTP1.ReadTimeout     := 5000;
IdHTTP1.Request.Accept  := 'application/json';
IdHTTP1.Request.AcceptCharSet  := 'UTF-8';
IdHTTP1.Request.AcceptLanguage := 'sv';
IdHTTP1.Request.ContentType    := 'application/json';
Memo1.Text := IdHTTP1.Get('http://api.arbetsformedlingen.se/af/v0/platsannonser/7088149');

I have tried several charset but can not correct the Swedish characters like å,ä,ö in the response.

  • å becomes Ã¥
  • ä becomes ä
  • ö becomes ö

What am I doing wrong here?

In Delphi 7 System unit there's an UTF8ToAnsi() function. Use like this:

  Memo1.Text := UTF8ToAnsi(IdHTTP1.Get('http://api.arbetsformedlingen.se/af/v0/platsannonser/7088149'));

The result is correct in Delphi 7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM