反序列化Json遇到URL更改 [英] Deserialize Json encountered URL change
问题描述
我有一个由facebook api返回的Json字符串,我想将其转换为对象,我尝试同时使用Newton Json和JavaScriptSerializer.
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
将其强制转换为强类型对象或动态对象后,URL将更改为
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
此问题的原因是什么?
我尝试了url编码和解码,但是没有用.
I have tried url encoding and decoding, but it didn't work.
推荐答案
在JSON中,任何字符都可以由Unicode码转义序列表示,该序列定义为\u
,后跟4个十六进制数字(请参见
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; }
}
输出:
Hello
在您的示例URL中,\u0025
代表%
字符.因此,这两个URL实际上是等效的.这里没有问题.
In your example URL, \u0025
represents the %
character. So the two URLs are actually equivalent. There is no issue here.
这篇关于反序列化Json遇到URL更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!