I am trying to parse some json data in my Windows application. I had written some codes for the same. The code is error free but no data appears in my textblock. Here is my XAML
<TextBlock Name="acc1" Margin="180, 60, 0, 0" Text="{Binding Accnumber1}" Foreground="White" VerticalAlignment="Top" HorizontalAlignment="Left" FontFamily="Segoe UI" FontSize="22" />
<TextBlock Name="bal1" Margin="180, 90,0, 0" Text="{Binding Availablebalance}" Foreground="White" VerticalAlignment="Top" HorizontalAlignment="Left" FontFamily="Segoe UI" FontSize="22" />
<TextBlock Name="acc2" Margin="180, 140, 0, 0" Text="{Binding Accnumber2}" Foreground="White" VerticalAlignment="Top" HorizontalAlignment="Left" FontFamily="Segoe UI" FontSize="22" />
<TextBlock Name="bal2" Margin="180, 170, 0, 0" Text="{Binding Availablebalance}" Foreground="White" VerticalAlignment="Top" HorizontalAlignment="Left" FontFamily="Segoe UI" FontSize="22" />
and this my class file
public MainPage()
{
InitializeComponent();
CheckForAnimation();
BackKeyPress += OnBackKeyPressed;
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;
ProgressBarRequest.Visibility = System.Windows.Visibility.Visible;
webClient.DownloadStringAsync(new Uri("http://mobimybank.appspot.com/loginresponse.json"));
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
if (!string.IsNullOrEmpty(e.Result))
{
var root1 = JsonConvert.DeserializeObject<RootObject>(e.Result);
this.DataContext = root1;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
ProgressBarRequest.Visibility = System.Windows.Visibility.Collapsed;
}
}
This is the RootObject class file
public class Mybank
{
public string status { get; set; }
}
public class Account
{
public string Accnumber1 { get; set; }
public string Availablebalance { get; set; }
public string Accnumber2 { get; set; }
}
public class Accounts
{
public List<Account> Account { get; set; }
}
public class Loginresponse
{
public Mybank { get; set; }
public Accounts { get; set; }
}
public class RootObject
{
public Loginresponse loginresponse { get; set; }
}
When i added a watcher at data context it tells me the data is been fetched. But the data is not displayed in above given textblocks. please tell me the area i am doing things wrong or the correct method to display the data.