1

I've troubles with parsing json array of arrays using golang, all of them without names:

[[1594561500000, 1031.47571376], [1594562500000, 1031.43571376],[1595561500000, 1041.41376]]

Could you help me with it?

3
  • 1
    var v [][]float64; json.Unmarshal(input,&v) Commented Aug 10, 2021 at 0:21
  • ./prog.go:17:35: cannot use dataJson (type string) as type []byte in argument to json.Unmarshal Commented Aug 10, 2021 at 0:27
  • 1
    I suggest you read some introductory material on Go and its type system. Commented Aug 10, 2021 at 0:30

1 Answer 1

3

Don't forget to convert the string you use to hold the JSON to []byte first:

package main

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

func main() {
    s := []byte(`[[1594561500000, 1031.47571376], [1594562500000, 1031.43571376],[1595561500000, 1041.41376]]`)
    var nums [][]float64

    if err := json.Unmarshal(s, &nums); err != nil {
        log.Fatal(err)
    }

    fmt.Println(nums)
}

Try it on the Go Playground.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.