我从一个函数接收数据,该函数返回一个.apiFunc()
interface{}
我知道在这种特定情况下,返回的数据是诸如struct
type Data struct { hello string world int}
我不知道切片有多大(API可以发送一个或100个此类实体的JSON数组)。
我应该如何声明变量myData
,以便它是数据
切片,由apiFunc()
的返回值组成?
我知道那件事
ret := apiFunc() myData := ret.([]Data)
不起作用(它恐慌与interface conversion: interface {} is []interface {}, not []main.Data
)
当年话下
相关分类