我有json代码:
{
responses:
[{
photo:[{url:"YYYY"},{url:"YYYY"}]
},
{
photo:[{url:"XXXX"},{url:"XXXX"}]
}]
}
在我的应用程序中,我试图解析每个响应中的响应和照片。我尝试在主gridview 中使用gridview,但它不起作用。有什么方法可以实现吗?谢谢您的帮助!
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("ЧЧЧЧЧ");
string Text = await response.Content.ReadAsStringAsync();
List<RootObject> values = JsonConvert.DeserializeObject<List<RootObject>>(Text);
lvMain3.ItemsSource = values;
cvsMain.Source = values[0].trends;
public class Trend
{
public string Query { get; set; }
public string Name { get; set; }
private UIElement _control = new MyUserControl1();
public UIElement Control { get { return _control; } }
}
public class Location
{
public string Name { get; set; }
public int Woeid { get; set; }
}
public class RootObject
{
public string As_of { get; set; }
public List<Trend> trends { get; set; }
public string created_at { get; set; }
public List<Location> Locations { get; set; }
}
还有我将gridview放在主gridview中的xaml代码:
<Page.Resources>
<CollectionViewSource x:Name="cvsMain" ItemsPath="Persons"/>
</Page.Resources>
....
<GridView x:Name="lvMain3">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Height="410" Width="410" Background="Gray">
<GridView x:Name="lvMain4">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Height="410" Width="410" Background="Gray">
<TextBlock Text="{Binding Name}"/>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
实际的 JSON:
[
{
"as_of":"2012-08-31T15:31:55Z",
"trends":[
{
"query":"%23GDTHATXX",
"name":"#GDTHATXX",
"promoted_content":null,
"url":"http:\/\/twitter.com\/search\/?q=%23GDTHATXX",
"events":null
},
{
"query":"%23UnMundoEnElQue",
"name":"#UnMundoEnElQue",
"promoted_content":null,
"url":"http:\/\/twitter.com\/search\/?q=%23UnMundoEnElQue",
"events":null
}
]
},
{
"as_of":"2012-08-31T15:31:55Z",
"trends":[
{
"query":"%23GDTHATXX",
"name":"#GDTHATXX",
"promoted_content":null,
"url":"http:\/\/twitter.com\/search\/?q=%23GDTHATXX",
"events":null
},
{
"query":"%23UnMundoEnElQue",
"name":"#UnMundoEnElQue",
"promoted_content":null,
"url":"http:\/\/twitter.com\/search\/?q=%23UnMundoEnElQue",
"events":null
}
]
}
]