1

I have an Json string return by facebook api and I want to cast it to an object, I tried using both Newton Json and JavaScriptSerializer.

https://graph.facebook.com/v1.0/1111111111111/comments?limit=25&after=NTA\u00253D

After I cast it to a strongly typed object or a dynamic object, the url will be changed to

https://graph.facebook.com/v1.0/1111111111111/comments?limit=25&after=NTA%3D

What is the cause of this issue?

I have tried url encoding and decoding, but it didn't work.

Timeless
  • 7,338
  • 9
  • 60
  • 94

1 Answers1

1

In JSON, any character can be represented by a unicode escape sequence, which is defined as \u followed by 4 hexadecimal digits (see JSON.org). When you deserialize the JSON, each escape sequence is replaced by the actual unicode character. You can see this for yourself if you run the following example program:

class Program
{
    static void Main(string[] args)
    {
        string json = @"{ ""Test"" : ""\u0048\u0065\u006c\u006c\u006f"" }";
        Foo foo = JsonConvert.DeserializeObject<Foo>(json);
        Console.WriteLine(foo.Test);
    }
}

class Foo
{
    public string Test { get; set; }
}

Output:

Hello

In your example URL, \u0025 represents the % character. So the two URLs are actually equivalent. There is no issue here.

Brian Rogers
  • 125,747
  • 31
  • 299
  • 300