I have a json file in my application which i can read ok and get the string as UTF-8 from the read.
using (StreamReader file = File.OpenText(filePath))
{
string json = file.ReadToEndAsync().Result;
}
I have some special characters in the form of RegEx which include /:@~{+_&%$
This is fine. All working.
However, there is also instances of the £ sign inside the json file contained in a RegEx. When the json file is read using the code about (UTF-8 by default ), the £ character comes out and is shown in the string as a black diamond with a white question mark in the middle; as a result, some conditions fail due to the RegEx not being correct.
The reason for this is the encoding and that UTF-8 cant understand this because it should ( according to my knowledge ) be read using ISO-8859-1 format.
Now, when I change my code to read the JSON file using this standard
using (StreamReader file = new StreamReader(entityFilePath, Encoding.GetEncoding("iso-8859-1")))
I get the correct value of £ out in my string within the RegEx.
However if I ever want to use other Unicode values such as ÁÉÍÓÚáéíóú in my json file, reading it using ISO-8859-1 will cause them to be retrieved and interpreted incorrectly.
My question is, how do I safely and reliably read my json file to retrieve all the text intact and all the characters intact including the £ sign?
Kind regards