At a quick glance, the values at the bottom include "Value16", which I assume should be Value6, and the value assigned to it is a string value that is far too large to fit in an int.
Some property doesn't work from JSON parsing
Question
I have an Windows 8 app that read from website as Json and I made the class that contains property needed for parsing the Json file. The problem is when I binding the data to TextBlocks some values show's up and some don't even when I use the Url in the browser it's have info and not null!
public class Rootobject
{
public Player player { get; set; }
public Stats stats { get; set; }
public Dogtags dogtags { get; set; }
public Weapon[] weapons { get; set; }
public Kititem[] kititems { get; set; }
public Vehicle[] vehicles { get; set; }
public Vehiclecategory[] vehicleCategory { get; set; }
public Award[] awards { get; set; }
}
public class Player
{
public int id { get; set; }
public string game { get; set; }
public string plat { get; set; }
public string name { get; set; }
public string tag { get; set; }
public long dateCheck { get; set; }
public long dateUpdate { get; set; }
public long dateCreate { get; set; }
public object lastDay { get; set; }
public string country { get; set; }
public object countryName { get; set; }
public Rank rank { get; set; }
public int score { get; set; }
public int timePlayed { get; set; }
public string uId { get; set; }
public string uName { get; set; }
public string uGava { get; set; }
public long udCreate { get; set; }
public string blPlayer { get; set; }
public string blUser { get; set; }
public bool editable { get; set; }
public bool viewable { get; set; }
public bool adminable { get; set; }
public bool linked { get; set; }
}
and The XAML is:
<DataTemplate x:Key="playerTemp">
<Grid Width="400" HorizontalAlignment="Center" >
<StackPanel >
<StackPanel Orientation="Horizontal">
<TextBlock Text="Name:"/>
<TextBlock Text="{Binding Path=player.name}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Platform:"/>
<TextBlock Text="{Binding Path=player.plat}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Country:"/>
<TextBlock Text="{Binding Path=player.countryName}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Date Create:"/>
<TextBlock Text="{Binding Path=player.lastDay}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Last Update:"/>
<TextBlock Text="{Binding Path=player.dateUpdate}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Time Played:"/>
<TextBlock Text="{Binding Path=player.timeplayed}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Score:"/>
<TextBlock Text="{Binding Path=player.score}" />
</StackPanel>
</Grid>
</DataTemplate>
<GridView Name="myGridView" ItemTemplate="{StaticResource nameTemp}" VerticalAlignment="Stretch" Height="100" HorizontalAlignment="Center" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Center" Width="800"/>
And the parsing code is:
private ObservableCollection<Rootobject> root= new ObservableCollection<Rootobject>();
public Details()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
myGridView.ItemsSource = root;
}
private async Task<Root> DoIT()
{
string theUrl = "www.SomeUrl.com";
using (HttpClient client = new HttpClient())
{
Uri uri = new Uri(theUrl);
using (Stream stream = await client.GetStreamAsync(uri))
{
DataContractJsonSerializer serial = new DataContractJsonSerializer(typeof(Rootobject));
Rootobject root = (Rootobject)serial.ReadObject(stream);
var obj = root;
return obj;
}
}
private async void btnDoIT_Click(object sender, RoutedEventArgs e)
{
Root data = await DoIT();
root.Add(data);
}
The problem is all values in the TextBlocks works good except Value3 and Value6 and when I use the url in browser it gets:
{"player":{"id":860573104,"game":"bf4","plat":"pc","name":"MedoOmar2011","tag":"MAAO","dateCheck":1386060441862,"dateUpdate":1386060441862,"dateCreate":1385683079202,"lastDay":"20131128","country":"","countryName":null,"rank":{"nr":7,"imgLarge":"bf4/ranks/r7.png","img":"r7","name":"Lance Corporal II","needed":91000,"next":{"nr":8,"img":"r8","name":"Lance Corporal III","needed":115000,"curr":107666,"relNeeded":24000,"relCurr":16666,"relProg":69.44166666666666}},"score":107666,"timePlayed":21172,"
I can't show platand timePlay.
No correct solution
OTHER TIPS
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow