i want to return the below json response output from this function, so i can use that returned value in another function.
but in the for loop i cant able to do that
is there any solution for this.
func Search_num(mobilenumber string) {
//.......get request.......
body, err := io.ReadAll(search_res.Body)
if err != nil {
log.Fatalln(err)
}
defer search_res.Body.Close()
var jsonbody Response
if err := json.Unmarshal(body, &jsonbody); err != nil {
log.Fatalln(err)
}
for _, p := range jsonbody.Data {
output := fmt.Sprintf("Name : %s\nMobile : %s\nEmail : %s\nCarrier : %s\nCity : %s\n", p.Name, p.Phone.Mobile, p.INTaddress.Email, p.Phone.Carrier, p.Address.City)
}
return output
}
seen some solutions but didnt understood how to assign the below json fmt.Sprintf("Name : %s\nMobile : %s\nEmail : %s\nCarrier : %s\nCity : %s\n", p.Name, p.Phone.Mobile, p.INTaddress.Email, p.Phone.Carrier, p.Address.City) in a slice :|