{"id":18280,"date":"2017-06-30T19:53:59","date_gmt":"2017-06-30T23:53:59","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=18280"},"modified":"2019-01-18T10:30:28","modified_gmt":"2019-01-18T15:30:28","slug":"swift-4-json-with-encoder-and-encodable","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2017\/06\/30\/swift-4-json-with-encoder-and-encodable\/","title":{"rendered":"Swift 4: JSON With Encoder and Encodable"},"content":{"rendered":"<p><a href=\"https:\/\/swiftunboxed.com\/stdlib\/json-encoder-encodable\/\">Greg Heo<\/a>:<\/p>\n<blockquote cite=\"https:\/\/swiftunboxed.com\/stdlib\/json-encoder-encodable\/\">\n<p>Rather than pore through all the source code for encoding and decoding, let&rsquo;s take a different approach and step through a simple example: how does a single <code>Int<\/code> instance wind its way through <code>JSONEncoder<\/code> and become JSON data?<\/p>\n<p>[&#8230;]<\/p>\n<p>To summarize: our Swift values get turned into their Foundation object equivalents by <code>JSONEncoder<\/code> and friends, then these objects get JSON-ified by <code>JSONSerialization<\/code>.<\/p>\n<p>[&#8230;]<\/p>\n<p>Now what about the reverse, decoding? And how can you write custom encoders and decoders for formats other than JSON, say protocol buffers? Stay tuned for more, or why not dig into the code and see what you find?<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Greg Heo: Rather than pore through all the source code for encoding and decoding, let&rsquo;s take a different approach and step through a simple example: how does a single Int instance wind its way through JSONEncoder and become JSON data? [&#8230;] To summarize: our Swift values get turned into their Foundation object equivalents by JSONEncoder [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2019-01-18T15:30:31Z","apple_news_api_id":"05c6ef40-61ae-4206-9491-caec5f664463","apple_news_api_modified_at":"2019-01-18T15:30:32Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/ABcbvQGGuQgaUkcrsX2ZEYw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[31,507,46,30,71,1774,901],"class_list":["post-18280","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-json","tag-languagedesign","tag-mac","tag-programming","tag-swift-codable","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/18280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=18280"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/18280\/revisions"}],"predecessor-version":[{"id":18281,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/18280\/revisions\/18281"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=18280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=18280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=18280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}