{"id":303656,"date":"2020-05-15T15:00:10","date_gmt":"2020-05-15T15:00:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=303656"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=303656","title":{"rendered":"Go: \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f JSON \u0441 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0435\u0439, \u0438\u043b\u0438 \u043a\u0430\u043a \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 API"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/502176\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/pf\/hz\/xm\/pfhzxmp9antvvecnexqujg6pkzk.jpeg\" alt=\"image\"\/><\/p>\n<p>  \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u043d\u0435 \u0434\u043e\u0432\u0435\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0430 Go http-\u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e REST API \u0441 json-\u043e\u043c \u0432 \u0440\u043e\u043b\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043d\u043e \u0432 \u0445\u043e\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439. \u0420\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u0432 \u0447\u0435\u043c \u0441\u0443\u0442\u044c.<\/p>\n<p>  \u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0444\u043e\u0440\u043c\u0430\u0442 json \u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u0427\u0435\u0442\u044b\u0440\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0445: \u0441\u0442\u0440\u043e\u043a\u0430, \u0447\u0438\u0441\u043b\u043e, \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439, null; \u0438 \u0434\u0432\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0445 \u0442\u0438\u043f\u0430: \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 json \u043a\u043e\u0434\u0430 \u0441 \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u043f\u043e\u043b\u044f\u043c\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432:<\/p>\n<pre><code class=\"json\">{ \t&quot;name&quot;:&quot;qwerty&quot;, \t&quot;price&quot;:258.25, \t&quot;active&quot;:true, \t&quot;description&quot;:null, }<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0438. \u0427\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u2014 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043a\u0430\u0432\u044b\u0447\u0435\u043a. \u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439: true \u0438\u043b\u0438 false (\u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a). \u0418 \u0442\u0438\u043f null \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 null (\u0442\u0430\u043a\u0436\u0435 \u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a).<\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442, \u043f\u0440\u0438 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u043e\u0433\u043e \u043e\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 json-\u043a\u043e\u0434\u0430, \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u043f\u043e\u043b\u0435\u0439 (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e price) \u043f\u043e\u043c\u0438\u043c\u043e \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043c\u0435\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0447\u0438\u0441\u043b\u043e \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0430\u0445). \u0422. \u0435. \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0432 \u0432\u0438\u0434\u0435 \u0447\u0438\u0441\u043b\u0430, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u044d\u0442\u043e \u0436\u0435 \u0447\u0438\u0441\u043b\u043e \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438. \u0423\u043c\u0430 \u043d\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0443, \u043a\u0430\u043a \u043d\u0430 \u0442\u043e\u043c \u043a\u043e\u043d\u0446\u0435 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d \u043a\u043e\u0434, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u0442\u0430\u043a\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043d\u043e \u0432\u0438\u0434\u0438\u043c\u043e, \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0438\u0441 \u0441\u0430\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043e\u0440\u043e\u043c \u0438 \u0442\u044f\u043d\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432, \u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u0438 json \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043a \u0435\u0434\u0438\u043d\u043e\u043c\u0443 \u0444\u043e\u0440\u043c\u0430\u0442\u0443. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043d\u0430\u0434\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0435\u043c \u0447\u0442\u043e \u0435\u0441\u0442\u044c.<\/p>\n<p>  \u041d\u043e \u0434\u0430\u043b\u0435\u0435 \u043c\u0435\u043d\u044f \u0436\u0434\u0430\u043b\u043e \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u0435. \u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u043b\u0435 (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e active), \u043f\u043e\u043c\u0438\u043c\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 true \u0438 false, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u00abtrue\u00bb, \u00abfalse\u00bb, \u0438 \u0434\u0430\u0436\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 1 \u0438 0 (\u0438\u0441\u0442\u0438\u043d\u0430 \u0438 \u043b\u043e\u0436\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e).<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412\u0441\u044f \u044d\u0442\u0430 \u043f\u0443\u0442\u0430\u043d\u0438\u0446\u0430 \u0441 \u0442\u0438\u043f\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0431\u044b\u043b\u0430 \u0431\u044b \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e\u0439, \u0435\u0441\u043b\u0438 \u0431\u044b \u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b json \u0441\u043a\u0430\u0436\u0435\u043c \u043d\u0430 \u0441\u043b\u0430\u0431\u043e\u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c PHP, \u043d\u043e Go \u0438\u043c\u0435\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u0443\u044e \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044e, \u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0447\u0435\u0442\u043a\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u043e\u0433\u043e \u043f\u043e\u043b\u044f. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f active \u0432 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f, \u0438 \u043b\u044e\u0431\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f price \u2014 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439.<\/p>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f price.<\/p>\n<p>  \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c json-\u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"json\">[ \t{&quot;id&quot;:1,&quot;price&quot;:2.58}, \t{&quot;id&quot;:2,&quot;price&quot;:7.15} ]<\/code><\/pre>\n<p>  \u0422. \u0435. json \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u043b\u044f\u043c\u0438 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e json-\u0430 \u043d\u0430 Go \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"go\">type Target struct { \tId    int     `json:&quot;id&quot;` \tPrice float64 `json:&quot;price&quot;` }  func main() { \tjsonString := `[{&quot;id&quot;:1,&quot;price&quot;:2.58}, \t\t\t\t\t{&quot;id&quot;:4,&quot;price&quot;:7.15}]`  \ttargets := []Target{}  \terr := json.Unmarshal([]byte(jsonString), &targets) \tif err != nil { \t\tfmt.Println(err) \t\treturn \t}  \tfor _, t := range targets { \t\tfmt.Println(t.Id, &quot;-&quot;, t.Price) \t} }<\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043c\u044b \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u043b\u0435 id \u0432 \u0442\u0438\u043f int, \u0430 \u043f\u043e\u043b\u0435 price \u0432 \u0442\u0438\u043f float64. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u0448 json-\u043a\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"json\">[ \t{&quot;id&quot;:1,&quot;price&quot;:2.58}, \t{&quot;id&quot;:2,&quot;price&quot;:&quot;2.58&quot;}, \t{&quot;id&quot;:3,&quot;price&quot;:7.15}, \t{&quot;id&quot;:4,&quot;price&quot;:&quot;7.15&quot;} ]<\/code><\/pre>\n<p>  \u0422. \u0435. \u043f\u043e\u043b\u0435 price \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0442\u0430\u043a \u0438 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f price \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u0442\u0438\u043f float64, \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0437\u043e\u0432\u0443\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u043e \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0442\u0438\u043f\u043e\u0432. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043d\u0438 float64, \u043d\u0438 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u0442\u0438\u043f \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f, \u0438 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0441\u0432\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0442\u0438\u043f \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 CustomFloat64 \u0441 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u0435\u043c Float64 \u0442\u0438\u043f\u0430 float64. <\/p>\n<pre><code class=\"go\">type CustomFloat64 struct{ \tFloat64 float64 }<\/code><\/pre>\n<p>  \u0418 \u0441\u0440\u0430\u0437\u0443 \u0443\u043a\u0430\u0436\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u043b\u044f \u043f\u043e\u043b\u044f Price \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 Target:<\/p>\n<pre><code class=\"go\">type Target struct { \tId    int           `json:&quot;id&quot;` \tPrice CustomFloat64 `json:&quot;price&quot;` }<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044f c \u0442\u0438\u043f\u043e\u043c CustomFloat64. <\/p>\n<p>  \u0412 \u043f\u0430\u043a\u0435\u0442\u0435 \u00abencoding\/json\u00bb \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0434\u0432\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430: <a href=\"https:\/\/godoc.org\/encoding\/json#RawMessage.MarshalJSON\">MarshalJSON<\/a> \u0438 <a href=\"https:\/\/godoc.org\/encoding\/json#RawMessage.UnmarshalJSON\">UnmarshalJSON<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0434\u043b\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<p>  \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u043e\u0434 UnmarshalJSON \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 CustomFloat64. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0442\u0440\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435 \u043c\u0435\u0442\u043e\u0434\u0430, \u0438\u043d\u0430\u0447\u0435 \u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043d\u0435 \u0432\u044b\u0434\u0430\u0441\u0442 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<pre><code class=\"go\">func (cf *CustomFloat64) UnmarshalJSON(data []byte) error {<\/code><\/pre>\n<p>  \u041d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043b\u0430\u0439\u0441 \u0431\u0430\u0439\u0442 (data), \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e json. \u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0430\u0439\u0442 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443, \u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u0442\u043e\u043c \u0432\u0438\u0434\u0435, \u0432 \u043a\u0430\u043a\u043e\u043c \u043e\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 json. \u0422. \u0435. \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0442\u0438\u043f, \u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0434\u0432\u043e\u0439\u043d\u044b\u043c\u0438 \u043a\u0430\u0432\u044b\u0447\u043a\u0430\u043c\u0438 (\u00ab258\u00bb), \u0435\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0442\u0438\u043f, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a (258).<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043e\u0442\u043b\u0438\u0447\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043a\u0430\u0432\u044b\u0447\u043a\u043e\u0439. \u0422\u0430\u043a \u043a\u0430\u043a \u0441\u0438\u043c\u0432\u043e\u043b \u0434\u0432\u043e\u0439\u043d\u043e\u0439 \u043a\u0430\u0432\u044b\u0447\u043a\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 UNICODE \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0434\u0438\u043d \u0431\u0430\u0439\u0442, \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0431\u0430\u0439\u0442 \u0441\u043b\u0430\u0439\u0441\u0430 data, \u0441\u0440\u0430\u0432\u043d\u0438\u0432 \u0435\u0433\u043e \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u0432 UNICODE. \u042d\u0442\u043e \u043d\u043e\u043c\u0435\u0440 34. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0441\u0438\u043c\u0432\u043e\u043b \u043d\u0435 \u0440\u0430\u0432\u043d\u043e\u0437\u043d\u0430\u0447\u0435\u043d \u0431\u0430\u0439\u0442\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0431\u0430\u0439\u0442\u0430. \u0421\u0438\u043c\u0432\u043e\u043b\u0443 \u0432 Go \u0440\u0430\u0432\u043d\u043e\u0437\u043d\u0430\u0447\u0435\u043d \u0442\u0438\u043f rune (\u0440\u0443\u043d\u0430). \u0412 \u043d\u0430\u0448\u0435\u043c \u0436\u0435 \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044f:<\/p>\n<pre><code class=\"go\">if data[0] == 34 {<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0442\u0438\u043f, \u0438 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u043c\u0435\u0436\u0434\u0443 \u043a\u0430\u0432\u044b\u0447\u043a\u0430\u043c\u0438, \u0442. \u0435. \u0441\u043b\u0430\u0439\u0441 \u0431\u0430\u0439\u0442 \u043c\u0435\u0436\u0434\u0443 \u043f\u0435\u0440\u0432\u044b\u043c \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0431\u0430\u0439\u0442\u043e\u043c. \u0418\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0430\u0439\u0441\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0432 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u0442\u0438\u043f float64. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a \u043d\u0435\u043c\u0443 \u043c\u0435\u0442\u043e\u0434 json.Unmarshal, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u0432 \u043f\u043e\u043b\u0435 Float64 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b CustomFloat64.<\/p>\n<pre><code class=\"go\">err := json.Unmarshal(data[1:len(data)-1], &cf.Float64)<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0436\u0435 \u0441\u043b\u0430\u0439\u0441 data \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0441 \u043a\u0430\u0432\u044b\u0447\u043a\u0438, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0432 \u043d\u0435\u043c \u0443\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 json.Unmarshal \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a\u043e \u0432\u0441\u0435\u043c\u0443 \u0441\u043b\u0430\u0439\u0441\u0443 data.<\/p>\n<pre><code class=\"go\">err := json.Unmarshal(data, &cf.Float64)<\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u0435\u0442\u043e\u0434\u0430 UnmarshalJSON:<\/p>\n<pre><code class=\"go\">func (cf *CustomFloat64) UnmarshalJSON(data []byte) error { \tif data[0] == 34 { \t\terr := json.Unmarshal(data[1:len(data)-1], &cf.Float64) \t\tif err != nil { \t\t\treturn errors.New(&quot;CustomFloat64: UnmarshalJSON: &quot; + err.Error()) \t\t} \t} else { \t\terr := json.Unmarshal(data, &cf.Float64) \t\tif err != nil { \t\t\treturn errors.New(&quot;CustomFloat64: UnmarshalJSON: &quot; + err.Error()) \t\t} \t} \treturn nil }<\/code><\/pre>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435, \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0430 json.Unmarshal \u043a \u043d\u0430\u0448\u0435\u043c\u0443 json-\u043a\u043e\u0434\u0443, \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f price \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0441 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u0442\u0438\u043f float64, \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0437\u0430\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0432 \u043f\u043e\u043b\u0435 Float64 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b CustomFloat64.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 Target \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 json. \u041d\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 json.Marshal \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0442\u0438\u043f\u0443 CustomFloat64, \u0442\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432 \u0432\u0438\u0434\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041d\u0430\u043c \u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0435 price \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0427\u0442\u043e\u0431\u044b \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 CustomFloat64, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 MarshalJSON, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0442\u0440\u043e\u0433\u043e \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<pre><code class=\"go\">func (cf CustomFloat64) MarshalJSON() ([]byte, error) { \tjson, err := json.Marshal(cf.Float64) \treturn json, err }<\/code><\/pre>\n<p>  \u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435, \u044d\u0442\u043e \u043e\u043f\u044f\u0442\u044c \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 json.Marshal, \u043d\u043e \u0443\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u043d\u0435 \u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 CustomFloat64, \u0430 \u043a \u0435\u0435 \u043f\u043e\u043b\u044e Float64. \u0418\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0441\u043b\u0430\u0439\u0441 \u0431\u0430\u0439\u0442 \u0438 \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<p>  \u0412\u043e\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u043e\u043f\u0443\u0449\u0435\u043d\u0430 \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438, \u043d\u043e\u043c\u0435\u0440 \u0431\u0430\u0439\u0442\u0430 \u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u043c \u0434\u0432\u043e\u0439\u043d\u044b\u0445 \u043a\u0430\u0432\u044b\u0447\u0435\u043a \u0432\u044b\u043d\u0435\u0441\u0435\u043d \u0432 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443):<\/p>\n<pre><code class=\"go\">package main  import ( \t&quot;encoding\/json&quot; \t&quot;errors&quot; \t&quot;fmt&quot; )  type CustomFloat64 struct { \tFloat64 float64 }  const QUOTES_BYTE = 34  func (cf *CustomFloat64) UnmarshalJSON(data []byte) error { \tif data[0] == QUOTES_BYTE { \t\terr := json.Unmarshal(data[1:len(data)-1], &cf.Float64) \t\tif err != nil { \t\t\treturn errors.New(&quot;CustomFloat64: UnmarshalJSON: &quot; + err.Error()) \t\t} \t} else { \t\terr := json.Unmarshal(data, &cf.Float64) \t\tif err != nil { \t\t\treturn errors.New(&quot;CustomFloat64: UnmarshalJSON: &quot; + err.Error()) \t\t} \t} \treturn nil }  func (cf CustomFloat64) MarshalJSON() ([]byte, error) { \tjson, err := json.Marshal(cf.Float64) \treturn json, err }  type Target struct { \tId    int           `json:&quot;id&quot;` \tPrice CustomFloat64 `json:&quot;price&quot;` }  func main() { \tjsonString := `[{&quot;id&quot;:1,&quot;price&quot;:2.58}, \t\t\t\t\t{&quot;id&quot;:2,&quot;price&quot;:&quot;2.58&quot;}, \t\t\t\t\t{&quot;id&quot;:3,&quot;price&quot;:7.15}, \t\t\t\t\t{&quot;id&quot;:4,&quot;price&quot;:&quot;7.15&quot;}]`  \ttargets := []Target{}  \t_ := json.Unmarshal([]byte(jsonString), &targets)  \tfor _, t := range targets { \t\tfmt.Println(t.Id, &quot;-&quot;, t.Price.Float64) \t}  \tjsonStringNew, _ := json.Marshal(targets) \tfmt.Println(string(jsonStringNew)) }<\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"bash\">1 - 2.58 2 - 2.58 3 - 7.15 4 - 7.15 [{&quot;id&quot;:1,&quot;price&quot;:2.58},{&quot;id&quot;:2,&quot;price&quot;:2.58},{&quot;id&quot;:3,&quot;price&quot;:7.15},{&quot;id&quot;:4,&quot;price&quot;:7.15}]<\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 json-\u0430 \u0441 \u043d\u0435\u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u043e\u043b\u044f.<\/p>\n<p>  \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c json-\u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"json\">[ \t{&quot;id&quot;:1,&quot;active&quot;:true}, \t{&quot;id&quot;:2,&quot;active&quot;:&quot;true&quot;}, \t{&quot;id&quot;:3,&quot;active&quot;:&quot;1&quot;}, \t{&quot;id&quot;:4,&quot;active&quot;:1}, \t{&quot;id&quot;:5,&quot;active&quot;:false}, \t{&quot;id&quot;:6,&quot;active&quot;:&quot;false&quot;}, \t{&quot;id&quot;:7,&quot;active&quot;:&quot;0&quot;}, \t{&quot;id&quot;:8,&quot;active&quot;:0}, \t{&quot;id&quot;:9,&quot;active&quot;:&quot;&quot;} ]<\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u0435 active \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f \u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439: true \u0438 false. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0432 \u0445\u043e\u0434\u0435 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044e true \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442: true (\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435), \u00abtrue\u00bb (\u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435), \u00ab1\u00bb (\u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435), 1 (\u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435). \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044e false \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442: false (\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435), \u00abfalse\u00bb (\u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435), \u00ab0\u00bb (\u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435), 0 (\u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435), &quot;&quot; (\u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430).<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u0430 \u043f\u043e\u043b\u044f Active \u0441\u0440\u0430\u0437\u0443 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0442\u0438\u043f CustomBool:<\/p>\n<pre><code class=\"go\">type Target struct { \tId     int        `json:&quot;id&quot;` \tActive CustomBool `json:&quot;active&quot;` }<\/code><\/pre>\n<p>  CustomBool \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0441 \u043e\u0434\u043d\u0438\u043c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u0435\u043c Bool \u0442\u0438\u043f\u0430 bool:<\/p>\n<pre><code class=\"go\">type CustomBool struct { \tBool bool }<\/code><\/pre>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043c\u0435\u0442\u043e\u0434 UnmarshalJSON. \u0421\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"go\">func (cb *CustomBool) UnmarshalJSON(data []byte) error { \tswitch string(data) { \tcase `&quot;true&quot;`, `true`, `&quot;1&quot;`, `1`: \t\tcb.Bool = true \t\treturn nil \tcase `&quot;false&quot;`, `false`, `&quot;0&quot;`, `0`, `&quot;&quot;`: \t\tcb.Bool = false \t\treturn nil \tdefault: \t\treturn errors.New(&quot;CustomBool: parsing \\&quot;&quot; + string(data) + &quot;\\&quot;: unknown value&quot;) \t} }<\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u043b\u0435 active \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 switch-case \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043e \u0442\u043e\u043c, \u0447\u0435\u043c\u0443 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f Bool \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b CustomBool. \u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u0434\u0432\u0430 \u0431\u043b\u043e\u043a\u0430 case. \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 true, \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u2014 false. <\/p>\n<p>  \u041f\u0440\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0440\u043e\u043b\u044c \u0433\u0440\u0430\u0432\u0438\u0441\u0430 (\u044d\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u043a\u0430\u0432\u044b\u0447\u043a\u0430 \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0448\u0435 \u0441 \u0431\u0443\u043a\u0432\u043e\u0439 \u0401 \u0432 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0439 \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u043a\u0435). \u0414\u0430\u043d\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u043e\u0439\u043d\u044b\u0435 \u043a\u0430\u0432\u044b\u0447\u043a\u0438 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435. \u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u043c \u044f \u043e\u0431\u0440\u0430\u043c\u0438\u043b \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u043a\u0430\u0432\u044b\u0447\u043a\u0430\u043c\u0438 \u0438 \u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, `false` \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0435 false (\u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a, \u0442\u0438\u043f bool \u0432 json), \u0430 `\u00abfalse\u00bb` \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0435 \u00abfalse\u00bb (\u0441 \u043a\u0430\u0432\u044b\u0447\u043a\u0430\u043c\u0438, \u0442\u0438\u043f string \u0432 json). \u0422\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0438 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 `1` \u0438 `\u00ab1\u00bb` \u041f\u0435\u0440\u0432\u043e\u0435 \u2014 \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e 1 (\u0432 json \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a), \u0432\u0442\u043e\u0440\u043e\u0435 \u2014 \u0441\u0442\u0440\u043e\u043a\u0430 \u00ab1\u00bb (\u0432 json \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0441 \u043a\u0430\u0432\u044b\u0447\u043a\u0430\u043c\u0438). \u0412\u043e\u0442 \u044d\u0442\u0430 \u0437\u0430\u043f\u0438\u0441\u044c `&quot;&quot;` \u2014 \u044d\u0442\u043e \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u0422. \u0435. \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 json \u043e\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a: &quot;&quot;.<\/p>\n<p>  \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (true \u0438\u043b\u0438 false) \u043c\u044b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043f\u043e\u043b\u0435 Bool \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b CustomBool:<\/p>\n<pre><code class=\"go\">cb.Bool = true<\/code><\/pre>\n<p>  \u0412 \u0431\u043b\u043e\u043a\u0435 defaul \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"go\">return errors.New(&quot;CustomBool: parsing \\&quot;&quot; + string(data) + &quot;\\&quot;: unknown value&quot;)<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043c\u0435\u0442\u043e\u0434 json.Unmarshal \u043a \u043d\u0430\u0448\u0435\u043c\u0443 json-\u043a\u043e\u0434\u0443, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f active \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u0442\u0438\u043f bool.<\/p>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 MarshalJSON \u0434\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b CustomBool:<\/p>\n<pre><code class=\"go\">func (cb CustomBool) MarshalJSON() ([]byte, error) { \tjson, err := json.Marshal(cb.Bool) \treturn json, err }<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e. \u041c\u0435\u0442\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u044f Bool \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b CustomBool.<\/p>\n<p>  \u0412\u043e\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u043e\u043f\u0443\u0449\u0435\u043d\u0430 \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438):<\/p>\n<pre><code class=\"go\">package main  import ( \t&quot;encoding\/json&quot; \t&quot;errors&quot; \t&quot;fmt&quot; )  type CustomBool struct { \tBool bool }  func (cb *CustomBool) UnmarshalJSON(data []byte) error { \tswitch string(data) { \tcase `&quot;true&quot;`, `true`, `&quot;1&quot;`, `1`: \t\tcb.Bool = true \t\treturn nil \tcase `&quot;false&quot;`, `false`, `&quot;0&quot;`, `0`, `&quot;&quot;`: \t\tcb.Bool = false \t\treturn nil \tdefault: \t\treturn errors.New(&quot;CustomBool: parsing \\&quot;&quot; + string(data) + &quot;\\&quot;: unknown value&quot;) \t} }  func (cb CustomBool) MarshalJSON() ([]byte, error) { \tjson, err := json.Marshal(cb.Bool) \treturn json, err }  type Target struct { \tId     int        `json:&quot;id&quot;` \tActive CustomBool `json:&quot;active&quot;` }  func main() { \tjsonString := `[{&quot;id&quot;:1,&quot;active&quot;:true}, \t\t\t\t\t{&quot;id&quot;:2,&quot;active&quot;:&quot;true&quot;}, \t\t\t\t\t{&quot;id&quot;:3,&quot;active&quot;:&quot;1&quot;}, \t\t\t\t\t{&quot;id&quot;:4,&quot;active&quot;:1}, \t\t\t\t\t{&quot;id&quot;:5,&quot;active&quot;:false}, \t\t\t\t\t{&quot;id&quot;:6,&quot;active&quot;:&quot;false&quot;}, \t\t\t\t\t{&quot;id&quot;:7,&quot;active&quot;:&quot;0&quot;}, \t\t\t\t\t{&quot;id&quot;:8,&quot;active&quot;:0}, \t\t\t\t\t{&quot;id&quot;:9,&quot;active&quot;:&quot;&quot;}]`  \ttargets := []Target{}  \t_ = json.Unmarshal([]byte(jsonString), &targets)  \tfor _, t := range targets { \t\tfmt.Println(t.Id, &quot;-&quot;, t.Active.Bool) \t}  \tjsonStringNew, _ := json.Marshal(targets) \tfmt.Println(string(jsonStringNew)) }<\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"bash\">1 - true 2 - true 3 - true 4 - true 5 - false 6 - false 7 - false 8 - false 9 - false [{&quot;id&quot;:1,&quot;active&quot;:true},{&quot;id&quot;:2,&quot;active&quot;:true},{&quot;id&quot;:3,&quot;active&quot;:true},{&quot;id&quot;:4,&quot;active&quot;:true},{&quot;id&quot;:5,&quot;active&quot;:false},{&quot;id&quot;:6,&quot;active&quot;:false},{&quot;id&quot;:7,&quot;active&quot;:false},{&quot;id&quot;:8,&quot;active&quot;:false},{&quot;id&quot;:9,&quot;active&quot;:false}]<\/code><\/pre>\n<p>  <\/p>\n<h4>\u0412\u044b\u0432\u043e\u0434\u044b<\/h4>\n<p>  \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445. \u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 MarshalJSON \u0438 UnmarshalJSON \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f json-\u043a\u043e\u0434\u0430. \u041f\u043e\u043c\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u043b\u044f\u043c\u0438, \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0449\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 null.<\/p>\n<p>  \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445. \u0424\u043e\u0440\u043c\u0430\u0442 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f json \u2014 \u044d\u0442\u043e \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439, \u0438 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0435\u0433\u043e \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u043f\u0435\u0440\u0435\u0434 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0417\u0430 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u043d\u0430\u0434\u043e \u0441\u0442\u0440\u043e\u0433\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c.<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/502176\/\"> https:\/\/habr.com\/ru\/post\/502176\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/502176\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/pf\/hz\/xm\/pfhzxmp9antvvecnexqujg6pkzk.jpeg\" alt=\"image\"\/><\/p>\n<p>  \u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043c\u043d\u0435 \u0434\u043e\u0432\u0435\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0430 Go http-\u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e REST API \u0441 json-\u043e\u043c \u0432 \u0440\u043e\u043b\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043d\u043e \u0432 \u0445\u043e\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439. \u0420\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u0432 \u0447\u0435\u043c \u0441\u0443\u0442\u044c.<\/p>\n<p>  \u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0444\u043e\u0440\u043c\u0430\u0442 json \u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u0427\u0435\u0442\u044b\u0440\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0445: \u0441\u0442\u0440\u043e\u043a\u0430, \u0447\u0438\u0441\u043b\u043e, \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439, null; \u0438 \u0434\u0432\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0445 \u0442\u0438\u043f\u0430: \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 json \u043a\u043e\u0434\u0430 \u0441 \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u043f\u043e\u043b\u044f\u043c\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432:<\/p>\n<pre><code class=\"json\">{ \t&quot;name&quot;:&quot;qwerty&quot;, \t&quot;price&quot;:258.25, \t&quot;active&quot;:true, \t&quot;description&quot;:null, }<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0438. \u0427\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u2014 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043a\u0430\u0432\u044b\u0447\u0435\u043a. \u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439: true \u0438\u043b\u0438 false (\u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a). \u0418 \u0442\u0438\u043f null \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 null (\u0442\u0430\u043a\u0436\u0435 \u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a).<\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442, \u043f\u0440\u0438 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u043e\u0433\u043e \u043e\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 json-\u043a\u043e\u0434\u0430, \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u043f\u043e\u043b\u0435\u0439 (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e price) \u043f\u043e\u043c\u0438\u043c\u043e \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043c\u0435\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0447\u0438\u0441\u043b\u043e \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0430\u0445). \u0422. \u0435. \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0432 \u0432\u0438\u0434\u0435 \u0447\u0438\u0441\u043b\u0430, \u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u044d\u0442\u043e \u0436\u0435 \u0447\u0438\u0441\u043b\u043e \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438. \u0423\u043c\u0430 \u043d\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0443, \u043a\u0430\u043a \u043d\u0430 \u0442\u043e\u043c \u043a\u043e\u043d\u0446\u0435 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d \u043a\u043e\u0434, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u0442\u0430\u043a\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043d\u043e \u0432\u0438\u0434\u0438\u043c\u043e, \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0441\u0435\u0440\u0432\u0438\u0441 \u0441\u0430\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0433\u0440\u0435\u0433\u0430\u0442\u043e\u0440\u043e\u043c \u0438 \u0442\u044f\u043d\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432, \u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u0438 json \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043a \u0435\u0434\u0438\u043d\u043e\u043c\u0443 \u0444\u043e\u0440\u043c\u0430\u0442\u0443. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043d\u0430\u0434\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0435\u043c \u0447\u0442\u043e \u0435\u0441\u0442\u044c.<\/p>\n<p>  \u041d\u043e \u0434\u0430\u043b\u0435\u0435 \u043c\u0435\u043d\u044f \u0436\u0434\u0430\u043b\u043e \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u0435. \u041b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u043e\u043b\u0435 (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e active), \u043f\u043e\u043c\u0438\u043c\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 true \u0438 false, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u00abtrue\u00bb, \u00abfalse\u00bb, \u0438 \u0434\u0430\u0436\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 1 \u0438 0 (\u0438\u0441\u0442\u0438\u043d\u0430 \u0438 \u043b\u043e\u0436\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e).  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-303656","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303656"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303656\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}