馃敊 Regresar

Funci贸n reflect.FieldByIndex():

Go proporciona soporte integrado para la implementaci贸n de la reflexi贸n en tiempo de ejecuci贸n y permite que un programa manipule objetos con tipos arbitrarios con la ayuda del paquete reflect. La funci贸n reflect.FieldByIndex() en Go se utiliza para obtener el campo anidado correspondiente al 铆ndice. Para acceder a esta funci贸n, es necesario importar el paquete reflect en el programa.

func (v Value) FieldByIndex(index []int) Value

Sintaxis del c贸digo

package main

import (

"fmt"

"reflect"

)

func main() {

tt:= reflect.StructOf([]reflect.StructField{

{

Name: "Height",

Type: reflect.TypeOf(0.0),

Tag: `json:"height"`,

},

{

Name: "Name",

Type: reflect.TypeOf("abc"),

Tag: `json:"name"`,

},

})

fmt.Println(tt.FieldByIndex([]int{0}))

}

Salida de c贸digo

{Height float64 json:"height" 0 [0] false}