找到反射获取数组每一项数据类型的方法

This commit is contained in:
2025-02-08 21:27:40 +08:00
parent fce39068ca
commit 81975350c1
4 changed files with 24 additions and 11 deletions

View File

@ -14,6 +14,7 @@ import (
"git.zhangdeman.cn/zhangdeman/serialize"
"os"
"os/user"
"reflect"
"testing"
)
@ -23,6 +24,20 @@ import (
//
// Date : 17:55 2024/7/19
func Test_parser_Openapi3(t *testing.T) {
type A struct {
Name string `json:"name"`
}
type B struct {
List []A `json:"list"`
}
var b *B
tt := reflect.TypeOf(b)
fmt.Println(tt)
var bArr []*B
v := reflect.MakeSlice(reflect.TypeOf(bArr), 1, 1)
fmt.Println(v)
index9 := v.Index(0)
fmt.Println(index9, index9.Type())
current, _ := user.Current()
byteData, _ := os.ReadFile(current.HomeDir + "/Downloads/test-openapi-doc.json")
var data define.OpenapiDoc