“在System.ni.dll中发生了'System.Reflection.TargetInvocationException'类型的异常,但未在用户代码中处理”

时间:2014-07-11 10:32:05

标签: c# windows-phone-8

public partial class Page2 : PhoneApplicationPage
    {
        public Page2()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            List<name> transactionList = new List<name>();
            WebClient webClient = new WebClient();
            webClient.DownloadStringAsync(new Uri("URI"));
            webClient.DownloadStringCompleted += (Object senders, DownloadStringCompletedEventArgs es) =>
            {
                string json_arr = es.Result;
                /*the above statement throws the following exception.
"An exception of type 'System.Reflection.TargetInvocationException' occurred in System.ni.dll but was not handled in user code"*/
                if (es.Error == null)
                {
                    JArray jsonarray = JArray.Parse(json_arr);
                    for (int i = 0; i < jsonarray.Count; i++)
                    {
                        String str1= jsonarray[i].Value<String>("str1");
                        String str2= jsonarray[i].Value<String>("str2");
                        String str3= jsonarray[i].Value<String>("str3");
                        String str4= jsonarray[i].Value<String>("str4");
                        String str5= jsonarray[i].Value<String>("str5");
                        transactionList.Add(new name(str1,str2,str3,str4,str5));
                    }
                    TransactionList.ItemsSource = transactionList;
                }
            };
        }
    }

0 个答案:

没有答案