我最承认我可能忘记了一些非常简单的事情,但我不知道是什么
我有一堂课:
public class UserAgentInfo
{
public string agent_type { get; set; }
public string agent_name { get; set; }
public string agent_version { get; set; }
public string os_type { get; set; }
public string os_name { get; set; }
public string os_versionName { get; set; }
public string os_versionNumber { get; set; }
public string linux_distibution { get; set; }
}
然后我从 URL 中获取 Json 字符串并尝试将其反序列化为:
using (System.Net.WebClient wc = new System.Net.WebClient())
{
string json = wc.DownloadString("http://www.useragentstring.com/?getJSON=agent_type-agent_name-agent_version-os_type-os_name-os_versionName-os_versionNumber-linux_distibution&uas=" + o.Browser);
agentInfo = ServiceStack.Text.TypeSerializer.DeserializeFromString<UserAgentInfo>(json);
}
json
字符串是:
"{\"agent_type\":\"Browser\",\"agent_name\":\"Chrome\",\"agent_version\":\"28.0.1500.72\",\"os_type\":\"Windows\",\"os_name\":\"Windows 7\",\"os_versionName\":\"\",\"os_versionNumber\":\"\",\"linux_distibution\":\"Null\"}"
或者对于那些不习惯 C#
"{"agent_type":"Browser","agent_name":"Chrome","agent_version":"28.0.1500.72","os_type":"Windows","os_name":"Windows 7","os_versionName":"","os_versionNumber":"","linux_distibution":"Null"}"
返回的对象是:
{...UserAgentInfo}
agent_name: null
agent_type: null
agent_version: null
linux_distibution: null
os_name: null
os_type: null
os_versionName: null
os_versionNumber: null
我错过了什么?