You haven't said what you're trying to do, and the error tells you that p doesn't have a field called "jitem".
Perhaps what you are trying to do is to extract a member from a structure dynamically: that is, jitem is the *name* of a struct member, only known at runtime? In that case, you can use the Reflect package: https://go.dev/play/p/QxTsm7CqDWg But that's really ugly and I think you should avoid it if at all possible. Go is not Python. There are safer and simpler approaches, for example: https://go.dev/play/p/MlNoZvGiuVc https://go.dev/play/p/293uVj_usQ5 If all you're trying to do is pretty-print JSON, then encoding/json can do that for you: https://go.dev/play/p/0oIKG7dn1KQ or you can use a YAML library. On Monday, 25 July 2022 at 04:37:21 UTC+1 a.enrriqu...@gmail.com wrote: > Please help me with this > > > func printitem(r Response, jitem string) []string { > item := []string{} > for _, p := range r.Result { > item = append(item, jitem+":"+p.jitem) > } > return item > } > how to pass a variable to this, jitem > > p.jitem undefined (type struct{BlockNumber string "json:\"blockNumber\""; > TimeStamp string "json:\"timeStamp\""; Hash string "json:\"hash\""; Nonce > string "json:\"nonce\""; BlockHash string "json:\"blockHash\""; > TransactionIndex string "json:\"transactionIndex\""; From string > "json:\"from\""; To string "json:\"to\""; Value string "json:\"value\""; > Gas string "json:\"gas\""; GasPrice string "json:\"gasPrice\""; IsError > string "json:\"isError\""; TxreceiptStatus string > "json:\"txreceipt_status\""; Input string "json:\"input\""; ContractAddress > string "json:\"contractAddress\""; CumulativeGasUsed string > "json:\"cumulativeGasUsed\""; GasUsed string "json:\"gasUsed\""; > Confirmations string "json:\"confirmations\""} has no field or method > jitem)compilerMissingFieldOrMethod > <https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source%3Dgopls#MissingFieldOrMethod> > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e0e771c0-235f-4b49-a991-2f31bc4f4aa3n%40googlegroups.com.