나는 대부분의 아마 정말 간단 뭔가를 잊고 해요,하지만 난ServiceStack.Text 및 DeserializeFromString
내가 클래스가 무엇을 알아낼 수 없습니다 인정 : 내가 얻을 다음
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; }
}
을
이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
문자열은 다음과 같습니다 :
{...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
:
"{\"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"}"
에 사용하고 반환 된 객체가되지 않은 사람을위한?
반환 된 문자열이 말 그대로 첫 번째와 마지막 큰 따옴표와 이스케이프 된 따옴표를 사용하여 질문에 쓰는 경우 객체가 아닌 단일 문자열로 구문 분석됩니다. '{ "agent_type": "Browser", "agent_name": "Chrome", ...}'과 같이 보일 것입니다. 'C# '의 – JimmiTh
은'''과 같은 특수 문자를 포함한 문자열을 이스케이프 처리해야하므로'\ "'... – balexandre
그 점 옆에 있습니다. JSON 문자열은 C#으로 작성된 문자열 리터럴이 아니며 서비스에서 반환 된 문자열입니다. 이 문자열이'''로 시작하고 끝나고 다른 모든 문자를 이스케이프하면 JSON 객체로 구문 분석되지 않고 단일 JSON 문자열로 해석됩니다. 내가 묻는 이유는 다음과 같습니다. * 문자 그대로 * 당신이 대가로 얻는 것입니까? Visual Studio 디버거가 보여주는 것만 큼? – JimmiTh