Data binding with json C# silverlight for windows phone 7

Jul 17, 2015 at 7:49 PM
I am trying to solve a problem that I have couple of days now. I am building a windows mobile app (C# silverlight for windows phone NET FRAMEWORK 4)

I am sending a Http Request to a web service. I get my json respond, which looks like this:


I also have this class in my project:

public class ProfileOptions
public string name { get; set; }
public string address { get; set; }
public string city { get; set; }
public string sum_points { get; set; }

Now I am getting the values of this json and put them inside a List:

JSonReader jr = new JSonReader();
IJSonObject json = jr.ReadAsJSonObject(_result);

IEnumerable items = json.ArrayItems;
List<object> ListObject = new List<object>();
foreach (var arrayItem in json.ArrayItems)
 foreach (var objItem in arrayItem.ObjectItems)

The MessageBox.Show(..), shows me correctly the values that I want (something,mycity....etc). Next step is to check if the first value is 0, show me a Message, otherwise put these values in Listbox binding the values.

if (ListObject.ElementAt(0).ToString() == "0")
ListBoxShops.ItemsSource = ListObject;

The xaml file is like this:

<Grid Name="ProfileGrid">
<Button HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="Black" Background="#FFE74C3C" Opacity="0" IsEnabled="False" Width="455" Height="Auto" Name="LoginUserBtn" Content="Please login" BorderBrush="Black" Click="LoginUserBtn_Click" />
<Button HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="Black" Background="#FFE74C3C" Opacity="0" IsEnabled="False" Width="455" Height="Auto" Name="FirstChenInBtn" Content="Go for your first check-in" BorderBrush="Black" Click="FirstChenInBtn_Click" />
<ListBox x:Name="ListBoxShops" ItemsSource="{Binding}" Height="540" Margin="0,65,0,0">
          <StackPanel Orientation="Horizontal">
     <!--<Canvas Width="50" Height="50" Name="IconProduct"></Canvas>-->
      <TextBlock Text="{Binding name}" Width="150" Height="100" Foreground="Black"></TextBlock>
       <TextBlock Text="{Binding address}" Width="150" Height="100"></TextBlock>
       <TextBlock Text="{Binding city}" Width="150" Height="100"></TextBlock>
       <TextBlock Text="{Binding total_points}" Width="Auto" Height="100"></TextBlock>

I tried many things but without any results.. The weird thing is that I get no errors. The app is still running, but I can not see my values in the ListBox. Any help would be appreciated. thanks for your time
Jul 22, 2015 at 4:35 PM
I found my answer. Actually it was much simpler than I thougt.Anyway, if anyone interesting,
List<ProfileOptions> ListProfileOptions = new List<ProfileOptions>();
                for (int i = 0; i < json.Count; i++)
                    ProfileOptions ProfileOptionsObj = new ProfileOptions();
           = json[i][2].ToString();
                    ProfileOptionsObj.address = json[i][3].ToString();
           = json[i][4].ToString();
                    ProfileOptionsObj.sum_points = json[i][5].ToString();
                //insert into ListBox all the values
                ListBoxShops.ItemsSource = ListProfileOptions;