Can someone explain what's going on here?

blov · · 57 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<pre><code>package main import ( &#34;encoding/json&#34; &#34;reflect&#34; ) func main() { t, _ := json.Marshal(20) println(string(t)) println(reflect.TypeOf(t).String()) println(len(t)) for _, b := range(t) { println(b) } } </code></pre> <p>The output on &#34;go run&#34; is: 20 []uint8 2 50 48</p> <p>Where did 50 &amp; 48 come from?</p> <hr/>**评论:**<br/><br/>singular_pirate: <pre><p>50 and 48 are the values of the codepoints of &#39;2&#39; and &#39;0&#39;.</p> <p>Example: <a href="" rel="nofollow"></a></p> <p>Reference: <a href="" rel="nofollow"></a></p></pre>ikickrobots: <pre><p>Ok. Thank you.</p></pre>natefinch: <pre><p>protip: never drop the error, even in examples. I can&#39;t tell you how many times I&#39;ve done that and regretted it when I did something dumb. Just throw a <code>if err != nil { log.Fatal(err) }</code> in there for kicks. It&#39;ll save you a headache one day.</p></pre>dilap: <pre><p>this is good advice.</p> <p>if you want to make it slightly less of a pain for throwaway scripts, just have a function like</p> <pre><code>func check(err error) { if(err != nil) { log.Fatal(err) } } </code></pre> <p>so then you just need to insert <code>check(err)</code> in your code, which is close to painless.</p></pre>
57 次点击  
加入收藏 微博
0 回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传