Why is the address of the variable passed in when the parameter type is interface {}

 
json.Unmarshal(data, &user)

json.Unmarhsal(data, user)
Mar.05,2021

Unmarshal parses the JSON-encoded data and stores the result
in the value pointed to by v. If v is nil or not a pointer,
Unmarshal returns an InvalidUnmarshalError.

@ Mu Youzhi you've seen the function prototype, take a closer look at the code comments above

officials have made it clear why. Unmarshal parses JSON encoded data and stores the results


syntactically speaking: passing a value is only a copy of the change, and you have to pass a pointer to change it.


although we can see that the second parameter is the output parameter, its most important function is to parse the JSON data into a specified struct structure object.

Menu