Java command to ignore Encoding

Asked

Viewed 162 times

0

I have the following situation, work with the software A of vehicle sales, in it has the opportunity to sell and this has a media (as the customer learned the opportunity), in addition to the store opportunities the software A receives information from a vehicle website, this sends us the media information encoding different from the media of the software A, so this is saved in the database with strange characters, Referral would look something like: Indicaá$Á&o.

The site sends something like:

header("Content-Type: text/html;  charset=utf-8");

...

$cliente = new client("http://999.999.999.999/WebService", false, $host, $porta, $usuario, $senha);

$chave_json = '[{ "chaveIntegracao" : "var1_",
    "valor" : "'.$_POST["var1"].'"},
        {"chaveIntegracao" : "var2_",
        "valor" : "'.$_POST["var2"].'"},
        {"chaveIntegracao" : "var3_",
        "valor" : "'.$_POST["var3"].'"},
        {"chaveIntegracao" : "var4_",
        "valor" : "'.$_POST["var4"].'"
      }]';

$dados[interfaceJson] = $chave_json;         

$result = $cliente->call('criarEvento', $dados, 'http://.../', 'http://.../');

Is there any way to take the strange code and convert, without having to treat every possibility of strange character ?

//transforma qualquer encoding em UTF-8
CastEncoding(vo.getMidia(),"UTF-8");
  • 1

    How are you reading the information coming from this external site? Are they coming as byte or as string? Ideally, this kind of thing has to be done on arrival, before bytes become string. After that turned, it would be hell to undo... Please post the code snippet that reads this entry (I imagine you must be creating a Reader somewhere without specifying the encoding, I’m sure?).

  • 2
  • @mgibsonbr The site sends a JSON with the information, but I’ll ask them to fix it, then I’ll do an UPDATE in the bank, I don’t have much choice, thanks for the help.

  • Blz, but how do you get this JSON? How is the Java code that reads this? Even if they don’t correct on their side, you can still get the right data if you know which is the encoding of this JSON.

  • @mgibsonbr This integration is not with me, I only work with integrated data, I will inform myself better and give you feedback.

  • @mgibsonbr I updated the question, this is the information that the site sends us, we receive with Web Service.

  • Are you sure the mistake is on their side? I think the error is on your side, but if you don’t show your Java code there’s no way I can help you...

Show 2 more comments

1 answer

1


Java command to ignore Encoding

This is not how the band plays, encoding is necessary to resolve how the text bits will be interpreted.


The site sends something like:

header("Content-Type: text/html;  charset=utf-8");

This means that the site is stating that its content is using the UTF-8 charset, but you need to check first if the PHP files are UTF-8, otherwise it will not work.

  • was identified that the encoding of the data sent by the client was WINDOWS-1251, in this case after the correction on the client side, will be updated in the incorrect data in the database.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.