JSON解组数组不起作用,但是相同的数据在javascript上也有效

I try to have some array values into JSON string where I send to the browser and in the browser is working fine to add some input fields dynamically, but when I try to check the data from that new fields on Go I try to unmarshal the same data but is not working because the values are empty.

This is the code:

package main

import "fmt"
import "encoding/json"


type PublicKey struct {
        Name        string   `json:"name"`
        Type        string   `json:"type"`
    Description string   `json:"description"`
    Values      []string `json:"values"`
}


func main() {

keysBody := []byte(`    
[
   [
      {
         "name":"fecha_inicio",
         "type":"date",
         "description":"Fecha de Inicio",
         "values":[
            ""
         ]
      }
   ],
   [
      {
         "name":"fecha_final",
         "type":"date",
         "description":"Fecha Final",
         "values":[
            ""
         ]
      }
   ],
   [
      {
         "name":"username",
         "type":"select",
         "description":"Usuario",
         "values":[
            "admin",
            "gus"
         ]
      }
   ]
]
`)


    keys := make([]PublicKey,0)
    json.Unmarshal(keysBody, &keys)
    fmt.Printf("%#v", keys)




}

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

This is the result:

[]main.PublicKey{main.PublicKey{Name:"", Type:"", Description:"", Values:[]string(nil)}, main.PublicKey{Name:"", Type:"", Description:"", Values:[]string(nil)}, main.PublicKey{Name:"", Type:"", Description:"", Values:[]string(nil)}}

This is the same code in javascript working fine:

parameterData contains the same JSON string

        var jsonMenus = JSON.parse(parameterData);     
        for (let i = 0; i < jsonMenus.length; i++) {
            let arr = jsonMenus[i];
            for (let j = 0; j < arr.length; j++) {
                //New DIV
                var newDiv = document.createElement("div");
                newDiv.setAttribute("class","w3-quarter");
                //console.log(arr[j].name + ' ' + arr[j].type + ' ' + arr[j].description);
                var label = document.createElement("Label");
                label.innerHTML = arr[j].description;
                label.setAttribute("class","w3-label");
                newDiv.appendChild(label);
                if (arr[j].type != 'select') {
                    var input = document.createElement("input");
                    input.type = arr[j].type;
                    input.name = arr[j].name;
                    input.setAttribute("class","w3-input w3-border w3-round");
                    newDiv.appendChild(input);
                } else {
                    var select = document.createElement("select");
                    select.name = arr[j].name;
                    var values = arr[j].values
                    for (let k = 0; k < values.length; k++) {
                        opt = document.createElement('option');
                        opt.value = values[k];
                        opt.innerHTML = values[k];
                        select.appendChild(opt);
                    }
                    select.setAttribute("class","w3-input w3-border w3-round");
                    newDiv.appendChild(select);
                }
                container.appendChild(newDiv);

Can anyone can help to have the JSON string working in both places?

Your json is a 2 dimensional array but you are trying to unmarshal to a single dimension array.

You need to unmarshal to an [][]PublicKey, here is the adjusted playground: https://play.golang.org/p/ykzzqtSPJCU.