admin管理员组

文章数量:1194346

In my Flutter app, using ChatGPT API (model gpt-4o-mini) and requesting a mixture of English and Hebrew in Json response, it receives the Hebrew as UTF8 Hex (each Hebrew character taking 2 bytes).

eg. "Sentence": "××××× ××× ××¦× ×©× ×¢×××ת ××× ×§××צ×ת ×× ×××× ×ת."

  • where each x above is 0xD7, and is followed by, for example, 0x94 (for Hebrew ה)

How can I convert this to displayable Hebrew?

I have tried 'Content-Type': 'application/json; charset=UTF-8' and also 'Content-Type': 'application/json' in the https request, with the same result.

The prompt used is: "Act as a Hebrew assistant that returns and replies valid, iterable JSON response, and provide a meaningful sentence in Hebrew, with Hebrew letters - not hexadecimal, with key Sentence, along with the English translation, with key Translation, for the Hebrew word: ".

A test using curl returns the Hebrew directly, as does ChatGPT on my MacBook Pro.

Any help is appreciated.

In my Flutter app, using ChatGPT API (model gpt-4o-mini) and requesting a mixture of English and Hebrew in Json response, it receives the Hebrew as UTF8 Hex (each Hebrew character taking 2 bytes).

eg. "Sentence": "××××× ××× ××¦× ×©× ×¢×××ת ××× ×§××צ×ת ×× ×××× ×ת."

  • where each x above is 0xD7, and is followed by, for example, 0x94 (for Hebrew ה)

How can I convert this to displayable Hebrew?

I have tried 'Content-Type': 'application/json; charset=UTF-8' and also 'Content-Type': 'application/json' in the https request, with the same result.

The prompt used is: "Act as a Hebrew assistant that returns and replies valid, iterable JSON response, and provide a meaningful sentence in Hebrew, with Hebrew letters - not hexadecimal, with key Sentence, along with the English translation, with key Translation, for the Hebrew word: ".

A test using curl returns the Hebrew directly, as does ChatGPT on my MacBook Pro.

Any help is appreciated.

Share Improve this question edited Jan 24 at 13:09 VLAZ 29k9 gold badges62 silver badges82 bronze badges asked Jan 24 at 13:08 Colin GColin G 4175 silver badges14 bronze badges 5
  • 3 "where each x above is 0xD7, and is followed by, for example, 0x94 (for Hebrew ה)" — So, how exactly are you displaying this where? Is it just a font issue, that your chosen font doesn't contain glyphs for Hebrew letters? How exactly did you determine that one x stands for 0xD7 0x94? – deceze Commented Jan 24 at 13:13
  • 2 The Hebrew letter ה is represented in UTF-8 as the sequence of bytes 0xD7 0x94. There is no "hex" in your response, just bytes. Your response is already UTF-8; you just need to decode it by calling utf8.decode on it. – jamesdlin Commented Jan 24 at 16:57
  • Thanks for responding. This app has two parts, the first shows Hebrew, while the second (ie. subject of this post) does not. Both parts have: style: const TextStyle( fontSize: 20.0, fontWeight: FontWeight.bold... - so I don't think the font is the problem. – Colin G Commented Jan 25 at 11:27
  • My code immediately after the ChatGPT results arrive - where cleanText string contains a portion of the Json response: Map<String, dynamic> map = json.decode(cleanText); print(map); - shows: {Sentence: ×××××...., Translation: ....} print(utf8.decode(map['Sentence'])); - gives TypeError: type 'String' is not a subtype of type 'List\<int\>' – Colin G Commented Jan 25 at 11:28
  • map is a JSON string. Therefore you have to use JSON methods to turn it into a JSON object first, and then decode the text. Or simply decode the whole JSON string as UTF8 – k314159 Commented Jan 25 at 11:34
Add a comment  | 

1 Answer 1

Reset to default 0

I found a solution by switching to use the dart_openai package, which returns Hebrew as Hebrew characters.

Thanks for your responses.

本文标签: utf 8How to convert UTF8 Hex to Hebrew letters in FlutterDartStack Overflow