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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.