Hello,
Welcome to our Microsoft Q&A platform!
I'm afraid you need to change the Root data = (Root)JsonSerializer.Deserialize<IEnumerable<Root>>(result);
to
Root data = JsonConvert.DeserializeObject<Root>(result);
From the Txt file your provided, we can see this result is not a list, the json formart is {......}
, so it cannot convert to System.Collections.IEnumerable , only this formart [......]
can be converted .
In addition, android_visibility
, ios_badgeCount
, ios_relevance_score
, isSMS
, priority
, ttl
these fields are null
in the Txt file your provided, however, they cannot be null
. So, I change these Property Type to object
in class Root.
public object android_visibility { get; set; }
For more information about IEnumerable Interface , you could refer to
https://learn.microsoft.com/en-us/dotnet/api/system.collections.ienumerable?view=net-6.0
------------update-----------
According to your StackLayout
, if you use BindableLayout.SetItemsSource
, the layout is a collection, you could set ItemTemplate
, refer to the following code :
var data = JsonConvert.DeserializeObject<Root>(json);
var bindObject = new Root[]
{
data,
};
BindableLayout.SetItemsSource(StackLayoutNotification, bindObject);
Xaml
<StackLayout x:Name="StackLayoutNotification">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label TextColor="Yellow" Grid.Row="0" Text="{Binding id}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HorizontalTextAlignment="Start" FontSize="20" LineBreakMode="WordWrap" />
</Grid>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
For more information, you could refer to https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/bindable-layouts
In addition, I noticed that there is only one object, you also could use MVVM and Data Binding to bind Root
class.
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hi @Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.)
I tried below code but notification is null
Would you mind printing this
result
and sharing it to me? or providing the json formart ofresult
?Here is the out in text file because it's larger than the allowed text in the reply box.
153702-result-outout.txt
Sign in to comment