

{"id":1596,"date":"2022-02-07T18:40:45","date_gmt":"2022-02-07T09:40:45","guid":{"rendered":"https:\/\/curecode.jp\/tech\/?p=1596"},"modified":"2022-02-07T18:40:45","modified_gmt":"2022-02-07T09:40:45","slug":"system-text-json-serailize-empty-json","status":"publish","type":"post","link":"https:\/\/curecode.jp\/tech\/system-text-json-serailize-empty-json\/","title":{"rendered":"[C#] System.Text.Json \u306e Serialize \u3067 JSON \u304c\u7a7a\u306b\u306a\u308b"},"content":{"rendered":"<h3>\u73fe\u8c61<\/h3>\n<p>\n  Xamarin \u306e\u958b\u767a\u3067 System.Text.Json \u3067\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3057\u3088\u3046\u3068\u3057\u305f\u3068\u304d\u306e\u8a71\u3067\u3059\u3002\n<\/p>\n<p>\n  Data \u3068\u3044\u3046 Json \u3078\u306e\u5909\u63db\u3092\u60f3\u5b9a\u3057\u305f\u30e2\u30c7\u30eb\u304c\u3042\u308b\u3068\u3057\u307e\u3059\u3002\uff08\u540d\u524d\u306f\u8aac\u660e\u7528\u306e\u4eee\u306e\u3082\u306e\u3067\u3059\uff09\n<\/p>\n<pre><code class=\"cs\">\r\n    class Data\r\n    {\r\n        [JsonPropertyName(\"id\")]\r\n        internal int Id { get; set; }\r\n\r\n        [JsonPropertyName(\"name\")]\r\n        internal string Name { get; set; }\r\n\r\n        [JsonPropertyName(\"message\"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]\r\n        internal string Message { get; set; }\r\n    }\r\n<\/code><\/pre>\n<p>\n  \u3053\u306e\u30af\u30e9\u30b9\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b Serialize \u3057\u3066\u3082\u4e2d\u8eab\u304c\u7a7a\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\n<\/p>\n<pre><code class=\"cs\">\r\nusing System.Text.Json;\r\n\r\n...\r\n\r\n    var data = new Data();\r\n    data.Id = 1;\r\n    data.Name = \"\u30c7\u30fc\u30bf1\";\r\n    data.Message = \"\u3053\u3093\u306b\u3061\u306f\";\r\n\r\n    \/\/ \u30b7\u30ea\u30a2\u30e9\u30a4\u30ba(\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092JSON\u306b\u3059\u308b)\r\n    var jsonText = JsonSerializer.Serialize(data);\r\n    \/\/ \"{}\" \u3068\u51fa\u529b\u3055\u308c\u308b\r\n    Debug.WriteLine(jsonText);\r\n<\/code><\/pre>\n<p>\n  JsonSerializerOptions \u306a\u3069\u306e\u305b\u3044\u304b\u3068\u601d\u3044\u3001\u3044\u308d\u3044\u308d\u8a66\u3057\u307e\u3057\u305f\u304c\u3001\u7d50\u679c\u7684\u306b\u306f\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u95a2\u4fc2\u3042\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002\n<\/p>\n<h3>\u89e3\u6c7a<\/h3>\n<p>\n  \u4ee5\u4e0b\u306e\u3088\u3046\u306b <strong>\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u5bfe\u8c61\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306f public \u306b<\/strong> \u3057\u305f\u3068\u3053\u308d\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3057\u305f Json \u304c\u53d6\u5f97\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\n<\/p>\n<pre><code class=\"cs\">\r\n    public class Data\r\n    {\r\n        [JsonPropertyName(\"id\")]\r\n        public int Id { get; set; }\r\n\r\n        [JsonPropertyName(\"name\")]\r\n        public string Name { get; set; }\r\n\r\n        [JsonPropertyName(\"message\"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]\r\n        public string Message { get; set; }\r\n    }\r\n<\/code><\/pre>\n<p>\n  public \u306b\u3057\u306a\u3044\u3068\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3055\u308c\u306a\u3044\u3068\u3044\u3046\u306e\u306f\u516c\u5f0f\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3082\u7279\u306b\u8a18\u8f09\u306f\u7121\u3044\u3088\u3046\u3067\u3059\u3002\n<\/p>\n<p>\n  internal \u306b\u3057\u3066\u3082\u30d3\u30eb\u30c9\u30a8\u30e9\u30fc\u306b\u306f\u306a\u3089\u306a\u3044\u306e\u3067\u3001\u306a\u304b\u306a\u304b\u6c17\u3065\u304d\u306b\u304f\u3044\u3068\u3053\u308d\u3067\u3059\u3002\n<\/p>\n<h3>IT\u30a8\u30f3\u30b8\u30cb\u30a2\u52df\u96c6\u4e2d\uff01<\/h3>\n<p>\u30ad\u30e5\u30a2\u30b3\u30fc\u30c9\u682a\u5f0f\u4f1a\u793e\u306fIT\u30a8\u30f3\u30b8\u30cb\u30a2\u3092\u52df\u96c6\u3057\u3066\u304a\u308a\u307e\u3059\u3002\u5c11\u4eba\u6570\u306e\u8077\u5834\u306a\u306e\u3067\u3001\u4e0a\u6d41\u30fb\u4e0b\u6d41\u3084\u30b5\u30fc\u30d0\u30fc\u30fb\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5bfe\u5fdc\u306e\u57a3\u6839\u306a\u304f\u3001\u3042\u306a\u305f\u306e\u5f37\u307f\u3092\u6d3b\u304b\u3057\u306a\u304c\u3089 \u3044\u308d\u3044\u308d\u306a\u3053\u3068\u306b\u30c1\u30e3\u30ec\u30f3\u30b8\u53ef\u80fd\u3067\u3059\u3002\u30a8\u30f3\u30b8\u30cb\u30a2\u3068\u3057\u3066\u306e\u672a\u7d4c\u9a13\u306e\u65b9\u3001\u7d4c\u9a13\u304c\u5c11\u306a\u3044\u65b9\u3082\u6b53\u8fce\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u4e0b\u8a18\u3088\u308aIT\u30a8\u30f3\u30b8\u30cb\u30a2\u52df\u96c6\u306e\u63a1\u7528\u60c5\u5831\u3092\u3054\u89a7\u3044\u305f\u3060\u3051\u307e\u3059\u3002<\/p>\n<div class=\"curecode_recruit_bn\">\n\t\t\t\t<a href=\"https:\/\/curecode.jp\/recruit\/itengineer\/\" target=\"_blank\" rel=\"noopener noreferrer\"><br \/>\n\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/curecode.jp\/tech\/wp-content\/themes\/tech\/images\/it_recruit.png?20241220\" alt=\"\u4e8b\u696d\u62e1\u5927\u306b\u4f34\u3044\u65b0\u3057\u3044\u9818\u57df\u306b\u4e00\u7dd2\u306b\u53d6\u308a\u7d44\u3093\u3067\u3044\u304f\u30e1\u30f3\u30d0\u30fc\u3092\u52df\u96c6\u3057\u307e\u3059\u3002\"  width=\"500\" height=\"180\"\/><br \/>\n\t\t\t\t<\/a>\n\t\t<\/div>\n<h3>\u30ad\u30e5\u30a2\u30b3\u30fc\u30c9\u516c\u5f0f\u30a4\u30f3\u30b9\u30bf\u30b0\u30e9\u30e0<\/h3>\n<p>\u30ad\u30e5\u30a2\u30b3\u30fc\u30c9\u682a\u5f0f\u4f1a\u793e\u306e\u65b0\u30b5\u30fc\u30d3\u30b9\u60c5\u5831\u3084\u3001\u30aa\u30d5\u30a3\u30b9\u30e9\u30a4\u30d5\u306e\u7d20\u6575\u306a\u77ac\u9593\u307e\u3067\u3002\u79c1\u305f\u3061\u306e\u65e5\u3005\u306e\u55b6\u307f\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<div class=\"curecode_recruit_bn\">\n\t\t\t\t<a href=\"https:\/\/www.instagram.com\/curecode\/\" target=\"_blank\" rel=\"noopener noreferrer\"><br \/>\n\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/curecode.jp\/tech\/wp-content\/themes\/tech\/images\/insta_bn.png?20241220\" alt=\"\u4e8b\u696d\u62e1\u5927\u306b\u4f34\u3044\u65b0\u3057\u3044\u9818\u57df\u306b\u4e00\u7dd2\u306b\u53d6\u308a\u7d44\u3093\u3067\u3044\u304f\u30e1\u30f3\u30d0\u30fc\u3092\u52df\u96c6\u3057\u307e\u3059\u3002\"  width=\"500\" height=\"180\"\/><br \/>\n\t\t\t\t<\/a>\n\t\t<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u73fe\u8c61 Xamarin \u306e\u958b\u767a\u3067 System.Text.Json \u3067\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3057\u3088\u3046\u3068\u3057\u305f\u3068\u304d\u306e\u8a71 [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[141],"tags":[156,182,148],"class_list":["post-1596","post","type-post","status-publish","format-standard","hentry","category-xamarin","tag-c","tag-json","tag-xamarin"],"_links":{"self":[{"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/posts\/1596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/comments?post=1596"}],"version-history":[{"count":4,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/posts\/1596\/revisions"}],"predecessor-version":[{"id":1600,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/posts\/1596\/revisions\/1600"}],"wp:attachment":[{"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/media?parent=1596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/categories?post=1596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/curecode.jp\/tech\/wp-json\/wp\/v2\/tags?post=1596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}