The Facebook graph API’s return to me the user’s email address as
foo\u0040bar.com.
in a JSON object. I need to convert it to
foo@bar.com.
There must be a built in method in .NET that changes the Unicode character expression (\u1234) to the actual unicode symbol.
Do you know what it is?
Note: I prefer not to use JSON.NET or JavaScriptSerializer for performance issues.
I think the problem is in my StreamReader:
requestUrl = "https://graph.facebook.com/me?access_token=" + accessToken;
request = WebRequest.Create(requestUrl) as HttpWebRequest;
try
{
using (HttpWebResponse response2 = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
reader = new StreamReader(response2.GetResponseStream(),System.Text.Encoding.UTF8);
string json = reader.ReadToEnd();
I tried different encodings for the StreamReader, UTF8, UTF7, Unicode, … none worked.
Many thanks!
Thanks to L.B for correcting me. The problem was not in the StreamReader.
Json responses are not binary data to convert to a string using some encodings. Instead they are strings correctly decoded by your browser or by
HttpWebResponseas in your example. You need a second procesing on it(regex, deserializers etc) to get the final data.See what you get with
webClient.DownloadString("https://graph.facebook.com/HavelVaclav?access_token=????")without any encodingWould your encoding change
\/to/?So, the problem is not in your
StreamReader.