0

I'm using Microsoft's graph API to get calendar events.

For Chinese, the Subject field text for the Event is nonsense.

For example, "世界您好" becomes "世界您好"

Microsoft's Graph API is returning correct data. The only problem is I don't know the encoding for the Subject field of each Event.

Trevy Burgess
  • 499
  • 5
  • 12
  • `var utf8 = Encoding.Default;` self-trolling turned to all the way to 11... naming some random encoding `utf8` does not really make code any more readable, even `a` or `l` would be less confusing. Could you please review your code and make sure to post [MCVE] into the question? – Alexei Levenkov Sep 02 '20 at 00:30

1 Answers1

0

Based on an answer from Mark Tolonen, it seems Microsoft Graph is encoding Calendar Events using "code page 1252, which is US Windows default".

Using his answer, this gave me the correct Subject field for the events.

public static string DecodeFromUtf8(this string utf8String)
{
    byte[] bytes = Encoding.GetEncoding(1252).GetBytes(utf8String);
    byte[] unicodeBytes = Encoding.Convert(Encoding.UTF8, Encoding.Unicode, bytes);
    return Encoding.Unicode.GetString(unicodeBytes);
}
Trevy Burgess
  • 499
  • 5
  • 12