I have a python script that generates a json file that is further used on a C# application. This is the code creating the export:
def put(data, filename):
with open(filename, 'w') as outfile:
json.dump(data, outfile, indent=4, ensure_ascii=False, encoding='utf8')
Then in the C# application I attempt to read it the following way:
public static string readFile(string filename)
{
using (StreamReader r = new StreamReader(filename))
{
return r.ReadToEnd();
}
}
//different file
string json_result = funcs.readFile(out_file);
VirtualMachine newvm = JsonConvert.DeserializeObject<MyClass>(json_result);
The problem is json_result
contains the characters \r\n
at each line break and fails to Deserialize the json.
I tried to check the encoding produced by the python script and according to SublimeText is u'Undefined'
How can I make python correctly encode the file for C# or make C# load it with the right encoding?