С первым файилом json deserialization делаю все получается, но со вторым (где 3 массива) не все данные читает.
Как решить эту проблему?
Здесь все нормально
Main Page
Class1[] mycollection = null;
public MainPage()
{
this.InitializeComponent();
string FilePath = Path.Combine(Package.Current.InstalledLocation.Path, "Class1.json");
using (StreamReader file = File.OpenText(FilePath))
{
var json = file.ReadToEnd();
Class1[] rootobject = (Class1[])JsonConvert.DeserializeObject(json, typeof(Class1[]));
foreach (var item in rootobject)
{
mycollection = item.details;
}
}
}
Class1
public class Rootobject
{
public Class1[] Property1 { get; set; }
}
public class Class1
{
public string itemType { get; set; }
public string type { get; set; }
public string title { get; set; }
public Detail[] details { get; set; }
}
public class Detail :Class1
{
public string detail_type { get; set; }
public string itemType { get; set; }
public string fill_color { get; set; }
public Gradient_Props gradient_props { get; set; }
public string icon_url { get; set; }
public string resource_url { get; set; }
}
public class Gradient_Props
{
public string gradient_stop_1 { get; set; }
public string gradient_stop_2 { get; set; }
}
Class DataTemplateSelector
public class MyDataTampletSelector : DataTemplateSelector
{
public DataTemplate Details { get; set; }
public DataTemplate Gradient {get; set;}
protected override DataTemplate SelectTemplateCore(object item )
{
if (item is Gradient_Props)
return Gradient;
if (item is Detail)
return Details;
return base.SelectTemplateCore(item);
}
}
XAML
<Page
x:Class="Task2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Task2"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<DataTemplate x:Key="GradientItemTemplate" x:DataType="local:Gradient_Props">
<TextBlock Text="{x:Bind gradient_stop_1}"/>
</DataTemplate>
<DataTemplate x:Key="DetalisItemSelection" x:DataType="local:Detail">
<Grid>
<StackPanel>
<Image Source="{x:Bind icon_url,Mode=OneWay}" Width="50" Height="50"/>
<TextBlock Text="{x:Bind resource_url , Mode=OneWay}"/>
<ColorPickerSlider Name="{x:Bind fill_color , Mode=OneWay}"/>
</StackPanel>
</Grid>
</DataTemplate>
<local:MyDataTampletSelector x:Key="MyDataTemplateSelector"
Details="{StaticResource DetalisItemSelection}"
Gradient="{StaticResource GradientItemTemplate}">
</local:MyDataTampletSelector>
</Page.Resources>
<ListView x:Name = "MyListView"
ItemsSource = "{x:Bind mycollection}"
ItemTemplateSelector = "{StaticResource MyDataTemplateSelector}">
</ListView>
</Page>
json
[
{
"itemType": "Canvas",
"type": "Color",
"title": "gen_color",
"details": [
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#000000"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#ffffff"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#feffdf"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#fdffab"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#fff9af"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#f9ff21"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#ffd933"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#ffbd39"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#ff8000"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#f05a28"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#f12d2d"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#ff0000"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#defcfc"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#a6e3e9"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#7efaff"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#53cde2"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#26baee"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#2470a0"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#235784"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#1b3764"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#4a0e5c"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#5e227f"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#a8026f"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#d22780"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#ff5da2"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#fa67ab"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#f48fb1"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#f9a1bc"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#c7f2e3"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#9ed9c5"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#73dbc4"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#1abb9c"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#219897"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#155e63"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#00454a"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#003545"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#28544b"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#227066"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#4a772f"
},
{
"detail_type": "Color",
"itemType": "Canvas",
"fill_color": "#7cbd1e"
}
]
},
{
"itemType": "Canvas",
"title": "effect_color_gradient",
"details": [
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#002092",
"gradient_stop_2": "#1AB9C8"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#F75070",
"gradient_stop_2": "#FFE194"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#2B0096",
"gradient_stop_2": "#E9649B"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#5A63D8",
"gradient_stop_2": "#CD90E1"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#FDE869",
"gradient_stop_2": "#00B1C1"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#FECF60",
"gradient_stop_2": "#974EF6"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#FFD529",
"gradient_stop_2": "#FD8440"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#C24078",
"gradient_stop_2": "#FFC3B9"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#00EAF8",
"gradient_stop_2": "#6D42EF"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#FF90D3",
"gradient_stop_2": "#3AEF3C"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#FFCD2C",
"gradient_stop_2": "#FF0663"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#FC1E50",
"gradient_stop_2": "#D2B0EF"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#EF14C5",
"gradient_stop_2": "#FFC160"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#7AE4FF",
"gradient_stop_2": "#FC2F5D"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#6CF6DA",
"gradient_stop_2": "#176DA0"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#FF0467",
"gradient_stop_2": "#FC7437"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#FD8041",
"gradient_stop_2": "#FF4CA1"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#FEB984",
"gradient_stop_2": "#FF5542"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#00FAC1",
"gradient_stop_2": "#C500E1"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#6FFF00",
"gradient_stop_2": "#005BFF"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#F8A2ED",
"gradient_stop_2": "#934EAE"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#5F86EC",
"gradient_stop_2": "#7C4CB0"
}
},
{
"detail_type": "Gradient",
"itemType": "Canvas",
"gradient_props": {
"gradient_stop_1": "#EB4B92",
"gradient_stop_2": "#CA76E3"
}
}
]
},
{
"itemType": "Canvas",
"title": "win_pattern",
"details": [
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_1.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_1.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_2.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_2.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_3.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_3.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_4.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_4.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_5.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_5.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_6.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_6.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_7.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_7.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_8.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_8.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_9.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_9.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_10.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_10.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_11.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_11.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_12.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_12.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_13.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_13.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_14.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_14.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_15.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_15.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_16.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_16.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_17.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_17.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_18.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_18.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_19.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_19.jpg"
},
{
"detail_type": "Pattern",
"itemType": "Canvas",
"icon_url": "http://pastatic.picsart.com/backgrounds_ver7/icons/i_bg_20.jpg",
"resource_url": "http://pastatic.picsart.com/backgrounds_ver7/2048/bg_20.jpg"
}
]
}
]
Class1
? Поставьте себя, на наше место, представьте, что вы говорите человеку, который совершенно не знает вас, ваш проект и что вы хотите сделать, вот как вы ему будете объяснять все это? Так? Также, посмотрите ваш предыдущий вопрос, я там делал форматирование, возьмите его за основу и сделайте также красиво и читаемо!{
, а десереализуете в массив, в этом случае json должен начинаться с[
.