K
K
Katya Smirnova2019-10-31 17:48:39
go
Katya Smirnova, 2019-10-31 17:48:39

json parsing in go?

Good evening, you need to parse json like this:

type Packet struct {
  Tunnel  string
  Message string
}

func main() {
  data := []byte(`{tunnel: "AS646484PNKL", message: {username: "Sireax", message: "Hello"}}`)

  // ... Дальше должен произойти парсинг
  //     json tunnel -> packet tunnel
  //     json message должен так и остаться в виде строки и попасть в packet message
  //     
  //     Должно получиться что-то в виде этого:
  //     packet.tunnel -> "AS646484PNKL"
  //     packet.message -> "{username: "Sireax", message: "Hello"}"
}

How can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
index0h, 2019-10-31
@sireax

https://golang.org/pkg/encoding/json/#example_Unmarshal
https://golang.org/pkg/encoding/json/#example_RawM...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question