0
正在此異常:解析JSON到C#的Windows Phone 8
類型的異常 'System.Reflection.TargetInvocationException' 發生在System.ni.dll但在用戶代碼中沒有處理
我的代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using trialss.Resources;
using System.IO;
using Newtonsoft.Json;
namespace trialss
{
public class Token
{
public string Token_No { get; set; }
public string Transaction_Date { get; set; }
public string Transaction_Amount { get; set; }
public string Purchased_Units { get; set; }
}
public class RootObject
{
public List<Token> Token { get; set; }
public int success { get; set; }
}
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private void clikeed(object sender, RoutedEventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri("my link"));
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
var rootObject = JsonConvert.DeserializeObject<RootObject>(e.Result);
foreach (var book in rootObject.Token)
{
}
}
}
}
我怎樣才能解決這個問題?
下面這行總是得到異常var rootObject = JsonConvert.DeserializeObject(e.Result); –
kyks