I have this json array and I need to extract the data:
b := [[{"client": " 321"}], [{"number": "3123"}]]
How can I structure the interface?
var f interface{}
err := json.Unmarshal(b, &f)
f = map[string]interface{}{
----> ?
}
I have this json array and I need to extract the data:
b := [[{"client": " 321"}], [{"number": "3123"}]]
How can I structure the interface?
var f interface{}
err := json.Unmarshal(b, &f)
f = map[string]interface{}{
----> ?
}
Is this what you are looking for?
You can test the code here.
package main
import (
"encoding/json"
"fmt"
"log"
)
func main() {
// test input (json.Unmarshal expects []byte)
b := []byte("[[{\"client\": \" 321\"}], [{\"number\": \"3123\"}]]")
// declare the target variable in the correct format
var f [][]map[string]string
// unmarshal the json
err := json.Unmarshal(b, &f)
if err != nil {
// handle error
log.Fatal(err)
}
// output result
fmt.Println(f)
}
For details see the comments in the code. Feel free to ask.