{"id":683,"date":"2020-03-25T17:37:46","date_gmt":"2020-03-25T08:37:46","guid":{"rendered":"https:\/\/todosoft.net\/blog\/?p=683"},"modified":"2021-03-14T05:39:11","modified_gmt":"2021-03-13T20:39:11","slug":"post-683","status":"publish","type":"post","link":"https:\/\/todosoft.net\/blog\/?p=683","title":{"rendered":"C#\u3067Json\u3092\u6271\u3046 Json.Net DeserializeObject\u7de8"},"content":{"rendered":"\n<p>\u30fb<a href=\"https:\/\/todosoft.net\/blog\/?p=527\">C#\u3067Json\u3092\u6271\u3046 DynamicJson\u7de8<\/a><br>\u30fb<a href=\"https:\/\/todosoft.net\/blog\/?p=674\">C#\u3067Json\u3092\u6271\u3046 Json.Net JToken\/JObject\/JArray\u7de8<\/a><br>\u30fb<a href=\"https:\/\/todosoft.net\/blog\/?p=683\">C#\u3067Json\u3092\u6271\u3046 Json.Net DeserializeObject\u7de8<\/a><br>\u30fbC#\u3067Json\u3092\u6271\u3046 System.Text.Json\u7de8<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Json.Net\u306b\u3064\u3044\u3066<\/h2>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/www.newtonsoft.com\/json\" target=\"_blank\">Json.NET &#8211; Newtonsoft<\/a><\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">App.xaml<\/h2>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">&lt;Application x:Class=\"WpfApp7.App\"\n             xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n             xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n             xmlns:local=\"clr-namespace:WpfApp7\"\n             StartupUri=\"View\\MainView.xaml\">\n    &lt;Application.Resources>\n         \n    &lt;\/Application.Resources>\n&lt;\/Application><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">WeatherEntity.cs<\/h2>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">using Newtonsoft.Json;\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace WpfApp7.DataEntity\n{\n    [JsonObject]\n    public class WeatherEntity\n    {\n        [JsonProperty(\"forecasts\")]\n        public List&lt;ForecastsEntity> Forecasts { get; set; }\n\n        [JsonProperty(\"title\")]\n        public string Title { get; set; }\n\n        [JsonProperty(\"description\")]\n        public DescriptionEntity Description { get; set; }\n    }\n\n    [JsonObject(\"forecasts\")]\n    public class ForecastsEntity\n    {\n        [JsonProperty(\"dateLabel\")]\n        public string DateLabel { get; set; }\n\n        [JsonProperty(\"telop\")]\n        public string Telop { get; set; }\n\n        [JsonProperty(\"date\")]\n        public string Date { get; set; }\n\n        [JsonProperty(\"image\")]\n        public ForecastsImageEntity Image { get; set; }\n    }\n\n    [JsonObject(\"image\")]\n    public class ForecastsImageEntity\n    {\n        [JsonProperty(\"width\")]\n        public int Width { get; set; }\n\n        [JsonProperty(\"url\")]\n        public string Url { get; set; }\n\n        [JsonProperty(\"title\")]\n        public string Title { get; set; }\n\n        [JsonProperty(\"height\")]\n        public int Height { get; set; }\n    }\n\n    [JsonObject(\"description\")]\n    public class DescriptionEntity\n    {\n        [JsonProperty(\"text\")]\n        public string Text { get; set; }\n\n        [JsonProperty(\"publicTime\")]\n        public DateTime PublicTime { get; set; }\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">MainView.xaml<\/h2>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">&lt;Window x:Class=\"WpfApp7.View.MainView\"\n        xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n        xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n        xmlns:d=\"http:\/\/schemas.microsoft.com\/expression\/blend\/2008\"\n        xmlns:mc=\"http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006\"\n        xmlns:i=\"http:\/\/schemas.microsoft.com\/xaml\/behaviors\"\n        xmlns:l=\"http:\/\/schemas.livet-mvvm.net\/2011\/wpf\"\n        xmlns:local=\"clr-namespace:WpfApp7.View\"\n        xmlns:vm=\"clr-namespace:WpfApp7.ViewModel\"\n        mc:Ignorable=\"d\"\n        Title=\"MainView\" Height=\"450\" Width=\"800\">\n\n    &lt;Window.DataContext>\n        &lt;vm:MainViewModel\/>\n    &lt;\/Window.DataContext>\n\n    &lt;i:Interaction.Triggers>\n        &lt;i:EventTrigger EventName =\"ContentRendered\">\n            &lt;l:LivetCallMethodAction MethodTarget=\"{Binding}\" MethodName=\"OnContentRendered\" \/>\n        &lt;\/i:EventTrigger>\n    &lt;\/i:Interaction.Triggers>\n\n    &lt;Grid>\n        &lt;Grid.RowDefinitions>\n            &lt;RowDefinition Height=\"auto\"\/>\n            &lt;RowDefinition Height=\"*\"\/>\n            &lt;RowDefinition Height=\"auto\"\/>\n        &lt;\/Grid.RowDefinitions>\n\n        &lt;Label Grid.Row=\"0\" Grid.Column=\"0\" Content=\"{Binding Path=Weather.Title}\"\/>\n\n        &lt;ListView Grid.Row=\"1\" Grid.Column=\"0\" ItemsSource=\"{Binding Path=Weather.Forecasts}\">\n            &lt;ListView.Style>\n                &lt;Style TargetType=\"ListView\">\n                    &lt;Setter Property=\"ScrollViewer.HorizontalScrollBarVisibility\" Value=\"Visible\"\/>\n                    &lt;Setter Property=\"ScrollViewer.VerticalScrollBarVisibility\" Value=\"Hidden\"\/>\n                &lt;\/Style>\n            &lt;\/ListView.Style>\n            &lt;ListView.ItemsPanel>\n                &lt;ItemsPanelTemplate>\n                    &lt;VirtualizingStackPanel Orientation=\"Horizontal\"\/>\n                &lt;\/ItemsPanelTemplate>\n            &lt;\/ListView.ItemsPanel>\n            &lt;ListView.ItemTemplate>\n                &lt;DataTemplate>\n                    &lt;StackPanel>\n                        &lt;Label Content=\"{Binding Path=Date}\"\/>\n                        &lt;Image Source=\"{Binding Path=Image.Url}\"\/>\n                        &lt;Label Content=\"{Binding Path=Telop}\"\/>\n                    &lt;\/StackPanel>\n                &lt;\/DataTemplate>\n            &lt;\/ListView.ItemTemplate>\n        &lt;\/ListView>\n\n        &lt;Label Grid.Row=\"2\" Grid.Column=\"0\" Content=\"{Binding Path=Weather.Description.Text}\"\/>\n    &lt;\/Grid>\n&lt;\/Window><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">MainViewModel.cs<\/h2>\n\n\n\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">using Newtonsoft.Json;\nusing Newtonsoft.Json.Linq;\nusing System;\nusing System.Collections.Generic;\nusing System.Collections.ObjectModel;\nusing System.Linq;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Threading.Tasks;\n\nnamespace WpfApp7.ViewModel\n{\n    public class MainViewModel : Livet.ViewModel\n    {\n        private DataEntity.WeatherEntity _Weather = null;\n        public DataEntity.WeatherEntity Weather\n        {\n            get\n            {\n                return _Weather;\n            }\n            set\n            {\n                _Weather = value;\n                RaisePropertyChanged();\n            }\n        }\n\n        public void OnContentRendered()\n        {\n            string strSource = \"\";\n\n            using (System.Net.WebClient objWebClient = new System.Net.WebClient())\n            {\n                \/\/ JSON\u30c7\u30fc\u30bf\u306e\u53d6\u5f97\n                strSource = objWebClient.DownloadString(\"http:\/\/weather.livedoor.com\/forecast\/webservice\/json\/v1?city=130010\");\n            }\n\n            \/\/ Unicode\u30a8\u30b9\u30b1\u30fc\u30d7\u6587\u5b57\u3092\u5143\u306b\u623b\u3059\n            strSource = Regex.Unescape(strSource);\n\n            \/\/ \u6307\u5b9a\u3057\u305f\u578b\u3067\u30c7\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\n            Weather = JsonConvert.DeserializeObject&lt;DataEntity.WeatherEntity>(strSource);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"443\" src=\"https:\/\/todosoft.net\/blog\/wp-content\/uploads\/2020\/03\/json.net_2.png\" alt=\"\" class=\"wp-image-685\" srcset=\"https:\/\/todosoft.net\/blog\/wp-content\/uploads\/2020\/03\/json.net_2.png 786w, https:\/\/todosoft.net\/blog\/wp-content\/uploads\/2020\/03\/json.net_2-300x169.png 300w, https:\/\/todosoft.net\/blog\/wp-content\/uploads\/2020\/03\/json.net_2-768x433.png 768w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u30fbC#\u3067Json\u3092\u6271\u3046 DynamicJson\u7de8\u30fbC#\u3067Json\u3092\u6271\u3046 Json.Net JToken\/JObject\/JArray\u7de8\u30fbC#\u3067Json\u3092\u6271\u3046 Json.Net DeserializeObject\u7de8\u30fbC#\u3067 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,20,15],"tags":[84,45,83],"class_list":["post-683","post","type-post","status-publish","format-standard","hentry","category-c","category-wpf","category-15","tag-deserializeobject","tag-json","tag-json-net"],"_links":{"self":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=683"}],"version-history":[{"count":2,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/683\/revisions"}],"predecessor-version":[{"id":686,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/683\/revisions\/686"}],"wp:attachment":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}