解析REST服务JSON响应(C#)
我对使用Windows Phone的C#相当陌生,最近开始使用Microsoft的教程()从API序列化JSON数据 我在尝试序列化从我自己的网站获得的JSON数据时遇到问题。然而,当我使用谷歌地图的一个API时,我不会遇到同样的问题 这是我用来从给定URL序列化JSON数据的代码解析REST服务JSON响应(C#),c#,json,rest,windows-phone,C#,Json,Rest,Windows Phone,我对使用Windows Phone的C#相当陌生,最近开始使用Microsoft的教程()从API序列化JSON数据 我在尝试序列化从我自己的网站获得的JSON数据时遇到问题。然而,当我使用谷歌地图的一个API时,我不会遇到同样的问题 这是我用来从给定URL序列化JSON数据的代码 public async void MakeRequest(string requestUrl) { try { HttpWebRequest requ
public async void MakeRequest(string requestUrl)
{
try
{
HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
Debug.WriteLine("Request object created");
using (var response = (HttpWebResponse)(await request.GetResponseAsync()))
{
Debug.WriteLine("Response object created");
if (response.StatusCode != HttpStatusCode.OK)
throw new Exception(String.Format(
"Server error (HTTP {0}: {1}).",
response.StatusCode,
response.StatusDescription));
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Response));
Debug.WriteLine("json serialized");
object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
Debug.WriteLine("Response object created");
//Response jsonResponse = objResponse as Response;
//this.postResponse = jsonResponse;
}
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
当我使用这个JSON数据时,上面的代码运行良好()
我得到以下调试输出
'MobileApp.WinPhone.exe'(CoreCLR:DefaultDomain):加载了'C:\windows\system32\mscorlib.ni.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载'C:\Data\SharedData\PhoneTools\AppxLayouts\8877204e-d7ab-4c2a-ba85-df930a47ce48VS.Debug_AnyCPU.Savidu Dias\MobileApp.WinPhone.exe'。已加载符号。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.RUNTIME.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\WinMetadata\windows.winmd'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.RUNTIME.INTEROPSERVICES.WINDOWSRUNTIME.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.DIAGNOSTICS.DEBUG.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.COLLECTIONS.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载'C:\Data\SharedData\PhoneTools\AppxLayouts\8877204e-d7ab-4c2a-ba85-df930a47ce48VS.Debug\u AnyCPU.Savidu Dias\MobileApp.DLL'。已加载符号。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.THREADING.TASKS.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\System.Net.Requests.ni.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\System.Net.ni.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\System.Runtime.WindowsRuntime.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\System.Net.Primitives.ni.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.RUNTIME.SERIALIZATION.JSON.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.SERVICEMODEL.WEB.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.IO.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
已创建请求对象
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\en-US\mscorlib.debug.resources.dll'。模块是在没有符号的情况下构建的。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.CORE.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
已创建响应对象
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.RUNTIME.SERIALIZATION.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
线程0x3b4已退出,代码为0(0x0)。
json序列化
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.XML.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.RUNTIME.SERIALIZATION.PRIMITIVES.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
已创建响应对象
程序“[340]MobileApp.WinPhone.exe”已退出,代码为-1(0xFFFFFF)
但是,当我尝试使用以下API()时,程序会出现运行时错误
这是我获得的调试输出
'MobileApp.WinPhone.exe'(CoreCLR:DefaultDomain):加载了'C:\windows\system32\mscorlib.ni.dll'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载'C:\Data\SharedData\PhoneTools\AppxLayouts\8877204e-d7ab-4c2a-ba85-df930a47ce48VS.Debug_AnyCPU.Savidu Dias\MobileApp.WinPhone.exe'。已加载符号。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\SYSTEM.RUNTIME.NI.DLL'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(CoreCLR:):加载了'C:\windows\system32\WinMetadata\windows.winmd'。已跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。
'MobileApp.WinPhone.exe'(公司