'0xEF' is an invalid escapable character within a JSON string

Viewed 944

I got this strange message when parsing a json configuration file:

"JsonReaderException: '0xEF' is an invalid escapable character within a JSON string. The string should be correctly escaped. LineNumber: 3 | BytePositionInLine: 11."

The content of the json file is:

{
  "books": {
    "Content": [
      "運作"
    ]
  }
}

There is no such char '0xEF' in the configuration file, and nothing to escape.

The C# code as following:

using Microsoft.Extensions.Configuration;

// ...

config = new ConfigurationBuilder()
  .AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "config.json"))
  .Build();

Any help would be appreciated.

Note:

  1. as I memtioned above, "there is no such char '0xEF' in the configuration file", but the message is showing "'0xEF' is an invalid escapable character within a JSON string". Where does it come from?

  2. The configuration file is the right file, all information posted above are double confirmed.

  3. The byte representaion of the word 運作 is: byte[] { 0xff 0xfe 0x4b 0x90 0x5c 0x4f }.

  4. The issue is created by the word "運", all other words are working fine. Is there certain words are not allowed as string in json file?

2 Answers

It seems that the file at initialization encoding is ANSI. Change encoding json file to UTF-8 BOM.

(") aka the Fullwidth Quotation Mark (FWQM) is not (") aka the Quotation Mark (QM).

FWQM (") is a character which has for UTF-8 encoding EF BC 82. Hence the origin of the 0xEF byte.

There is probably a FWQM (") instead of a QM (") somewhere in the JSon file.

Related