A Microsoft framework for building cross-platform mobile apps using .NET and C# with native performance and user interfaces.
How to access Nested JSON?
Anonymous
Hi,
I have below JSON from OneSignal REST API and I want to access the id from here:
public string id { get; set; }
Like this:
string message_id = (e.ItemData as Notification).id;
My ListView is binded this way:
Root data = JsonSerializer.Deserialize<Root>(result);
ListViewBrowseNotifications.ItemsSource = data.notifications;
Here is the full class:
public class Contents
{
public string en { get; set; }
public string ar { get; set; }
public string az { get; set; }
public string bs { get; set; }
public string ca { get; set; }
public string hr { get; set; }
public string cs { get; set; }
public string da { get; set; }
public string nl { get; set; }
public string et { get; set; }
public string fi { get; set; }
public string fr { get; set; }
public string ka { get; set; }
public string bg { get; set; }
public string de { get; set; }
public string el { get; set; }
public string hi { get; set; }
public string he { get; set; }
public string hu { get; set; }
public string id { get; set; }
public string it { get; set; }
public string ja { get; set; }
public string ko { get; set; }
public string lv { get; set; }
public string lt { get; set; }
public string ms { get; set; }
public string nb { get; set; }
public string fa { get; set; }
public string pl { get; set; }
public string pt { get; set; }
public string pa { get; set; }
public string ro { get; set; }
public string ru { get; set; }
public string sr { get; set; }
public string sk { get; set; }
public string es { get; set; }
public string sv { get; set; }
public string th { get; set; }
public string tr { get; set; }
public string uk { get; set; }
public string vi { get; set; }
}
public class Data
{
public string business { get; set; }
public string ad { get; set; }
}
public class Headings
{
public string en { get; set; }
}
public class ApnsAlert
{
}
public class Ios
{
public int successful { get; set; }
public int failed { get; set; }
public int errored { get; set; }
public int converted { get; set; }
public int received { get; set; }
}
public class Android
{
public int successful { get; set; }
public int failed { get; set; }
public int errored { get; set; }
public int converted { get; set; }
public int received { get; set; }
}
public class PlatformDeliveryStats
{
public Ios ios { get; set; }
public Android android { get; set; }
}
public class Notification
{
public object adm_big_picture { get; set; }
public object adm_group { get; set; }
public object adm_group_message { get; set; }
public object adm_large_icon { get; set; }
public object adm_small_icon { get; set; }
public object adm_sound { get; set; }
public object spoken_text { get; set; }
public object alexa_ssml { get; set; }
public object alexa_display_title { get; set; }
public object amazon_background_data { get; set; }
public object android_accent_color { get; set; }
public object android_group { get; set; }
public object android_group_message { get; set; }
public object android_led_color { get; set; }
public string android_sound { get; set; }
public int? android_visibility { get; set; }
public string app_id { get; set; }
public object big_picture { get; set; }
public string buttons { get; set; }
public bool? canceled { get; set; }
public object chrome_big_picture { get; set; }
public object chrome_icon { get; set; }
public object chrome_web_icon { get; set; }
public object chrome_web_image { get; set; }
public object chrome_web_badge { get; set; }
public object content_available { get; set; }
public Contents contents { get; set; }
public int converted { get; set; }
public Data data { get; set; }
public object delayed_option { get; set; }
public object delivery_time_of_day { get; set; }
public int errored { get; set; }
public List<object> excluded_segments { get; set; }
public int failed { get; set; }
public object firefox_icon { get; set; }
public string global_image { get; set; }
public Headings headings { get; set; }
public string id { get; set; }
public object include_player_ids { get; set; }
public List<string> include_external_user_ids { get; set; }
public List<string> included_segments { get; set; }
public object thread_id { get; set; }
public int? ios_badgeCount { get; set; }
public object ios_badgeType { get; set; }
public object ios_category { get; set; }
public string ios_interruption_level { get; set; }
public double? ios_relevance_score { get; set; }
public string ios_sound { get; set; }
public ApnsAlert apns_alert { get; set; }
public object target_content_identifier { get; set; }
public bool? isAdm { get; set; }
public bool? isAndroid { get; set; }
public bool? isChrome { get; set; }
public bool? isChromeWeb { get; set; }
public object isAlexa { get; set; }
public bool? isFirefox { get; set; }
public bool? isIos { get; set; }
public bool? isSafari { get; set; }
public bool? isWP { get; set; }
public bool? isWP_WNS { get; set; }
public bool? isEdge { get; set; }
public bool? isHuawei { get; set; }
public bool? isSMS { get; set; }
public object large_icon { get; set; }
public int? priority { get; set; }
public int queued_at { get; set; }
public int remaining { get; set; }
public int send_after { get; set; }
public int? completed_at { get; set; }
public object small_icon { get; set; }
public int successful { get; set; }
public object received { get; set; }
public object tags { get; set; }
public object filters { get; set; }
public object template_id { get; set; }
public int? ttl { get; set; }
public string url { get; set; }
public object web_url { get; set; }
public object app_url { get; set; }
public object web_buttons { get; set; }
public object web_push_topic { get; set; }
public object wp_sound { get; set; }
public object wp_wns_sound { get; set; }
public PlatformDeliveryStats platform_delivery_stats { get; set; }
public object ios_attachments { get; set; }
public object huawei_sound { get; set; }
public object huawei_led_color { get; set; }
public object huawei_accent_color { get; set; }
public string huawei_visibility { get; set; }
public object huawei_group { get; set; }
public object huawei_group_message { get; set; }
public object huawei_channel_id { get; set; }
public object huawei_existing_channel_id { get; set; }
public object huawei_small_icon { get; set; }
public object huawei_large_icon { get; set; }
public object huawei_big_picture { get; set; }
public string huawei_msg_type { get; set; }
public object throttle_rate_per_minute { get; set; }
public object sms_from { get; set; }
public object sms_media_urls { get; set; }
public object name { get; set; }
public object email_click_tracking_disabled { get; set; }
public object fcap_group_ids { get; set; }
public string fcap_status { get; set; }
public DateTime onesignal_completed_at
{
get
{
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
dtDateTime = dtDateTime.AddSeconds(Convert.ToDouble(completed_at)).ToLocalTime();
return dtDateTime;
}
}
}
public class Root
{
public int total_count { get; set; }
public int offset { get; set; }
public int limit { get; set; }
public List<Notification> notifications { get; set; }
}
Kindly help..
Thanks,
Jassim
Developer technologies | .NET | Xamarin
Developer technologies | .NET | Xamarin
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Sign in to answer