2014-02-18 43 views
2

我幾乎試圖在這裏和那裏搜索下一個2天組織。 這是我的JSON-例如(取與Web客戶端=> DownloadStringCompletedEventHandler):不要得到反序列化的json(jsonnet)被查看

{"order_id":"12345678","itemList":["235724","203224","222224","222324","230021"],"amount":["65","50","10","25","42"]} 

從json2sharp:

public class RootObject 
    { 
     public string order_id { get; set; } 
     public List<string> itemList { get; set; } 
     public List<string> amount { get; set; } 
    } 

我的Xaml:

<ListBox x:Name="MyListBox" Height="344" Margin="0,107,0,245"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
      <StackPanel Orientation="Horizontal"> 
       <Image Source="{Binding image}"/> 
       <TextBlock Text="{Binding order_id}"/> 
       <TextBlock Text="{Binding itemList}"/> 
       <TextBlock Text="{Binding amount}"/> 
      </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
</ListBox> 

我的CS:

private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
    { 
     if (e.Error != null) 
     { 
      return; 
     } 

     RootObject rootObject = JsonConvert.DeserializeObject<RootObject>(e.Result); 
     List<RootObject> myItems = rootObject.itemList.; 
     foreach (var item in myItems) 
     { 
      MyListBox.Items.Add(item); 
     } 

     Order_id.Text = rootObject.order_id.ToString(); 
     //MyListBox.ItemsSource = Root 
     //MyListBox.DataContext = RootObject; 
    } 

我能夠顯示字符串order_id給a,但我沒有列出itemlist +金額。 有人能讓我走向正確的方向嗎? 預先感謝您。

回答

0

嘗試:

CS:

 var result = "{'order_id':'12345678','itemList':['235724','203224','222224','222324','230021'],'amount':['65','50','10','25','42']}"; 
     var rootObject = JsonConvert.DeserializeObject<RootObject>(result); 

     var items = new List<RootObject> 
     { 
      rootObject 
     }; 

     MyListBox.ItemsSource = items; 

XAML:

 <ListBox x:Name="MyListBox" 
       Margin="{StaticResource PhoneMargin}"> 

      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <StackPanel Orientation="Vertical"> 
         <TextBlock> 
          <TextBlock.Inlines> 
           <Run Text="order_id:" /> 
           <Run Text="{Binding order_id}" /> 
          </TextBlock.Inlines> 
         </TextBlock> 
         <StackPanel Orientation="Horizontal"> 
          <TextBlock Text="ItemList: " /> 
          <ItemsControl ItemsSource="{Binding itemList}" /> 
         </StackPanel> 
         <StackPanel Orientation="Horizontal"> 
          <TextBlock Text="Amount: " /> 
          <ItemsControl ItemsSource="{Binding amount}" /> 
         </StackPanel> 
        </StackPanel> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 

     </ListBox> 
+0

感謝你爲這個,我終於可以去futher這個項目。 – mmeulstee

+0

@mmeulstee你能將我的答案標記爲你問題的答案嗎?謝謝 – ROMAN

+0

你去羅馬 – mmeulstee