E
E
Eugene2020-05-21 20:45:49
go
Eugene, 2020-05-21 20:45:49

How to parse json with changing structure?

VK sends the following response

{"access_token_XXXXXX":"533bacf01e11f55b536a565b57531ac114461ae8736d6506a3", "expires_in":0}


How to get the access_token_XXXXXX field if XXXXXX is a group id that is constantly changing?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Samsonov, 2020-05-21
@you_are_enot

jsonSource := `{"access_token_XXXXXX":"533bacf01e11f55b536a565b57531ac114461ae8736d6506a3", "expires_in":0}`

var raw map[string]interface{}
err := json.Unmarshal([]byte(jsonSource), &raw)
if err != nil {
  log.Fatal(err)
}

for key, val := range raw {
  fmt.Printf("%s: %v\n", key, val)
}

https://play.golang.org/p/_GA06JaJqr8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question