@kjk1/

gobook json parse arbitrary

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.3753597587469193","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImVuY29kaW5nL2pzb24iCgkiZm10IgoJImxvZyIKKQoKLy8gOnNob3cgc3RhcnQKdmFyIGpzb25TdHIgPSBgewoJIm5hbWUiOiAiSmFuZSIsCgkiYWdlIjogMjQsCgkiY2l0eSI6ICJueSIKfWAKCi8vIDpzaG93IGVuZAoKZnVuYyBtYWluKCkgewoJLy8gOnNob3cgc3RhcnQKCXZhciBkb2MgbWFwW3N0cmluZ11pbnRlcmZhY2V7fQoJZXJyIDo9IGpzb24uVW5tYXJzaGFsKFtdYnl0ZShqc29uU3RyKSwgJmRvYykKCWlmIGVyciAhPSBuaWwgewoJCWxvZy5GYXRhbGYoImpzb24uVW5tYXJzaGFsIGZhaWxlZCB3aXRoICclcydcbiIsIGVycikKCX0KCWZtdC5QcmludGYoImRvYzogJSN2XG4iLCBkb2MpCgluYW1lLCBvayA6PSBkb2NbIm5hbWUiXS4oc3RyaW5nKQoJaWYgIW9rIHsKCQlsb2cuRmF0YWxmKCJkb2MgaGFzIG5vIGtleSAnbmFtZScgb3IgaXRzIHZhbHVlIGlzIG5vdCBzdHJpbmdcbiIpCgl9CglmbXQuUHJpbnRmKCJuYW1lOiAlI3ZcbiIsIG5hbWUpCgkvLyA6c2hvdyBlbmQKfQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main

import (
	"encoding/json"
	"fmt"
	"log"
)

// :show start
var jsonStr = `{
	"name": "Jane",
	"age": 24,
	"city": "ny"
}`

// :show end

func main() {
	// :show start
	var doc map[string]interface{}
	err := json.Unmarshal([]byte(jsonStr), &doc)
	if err != nil {
		log.Fatalf("json.Unmarshal failed with '%s'\n", err)
	}
	fmt.Printf("doc: %#v\n", doc)
	name, ok := doc["name"].(string)
	if !ok {
		log.Fatalf("doc has no key 'name' or its value is not string\n")
	}
	fmt.Printf("name: %#v\n", name)
	// :show end
}