Here, I want the list "User" as a response. But it contains Message also. I want the message to be printed only once. Currently it is printing user.count times.
for (int i = 0; i < user.Count; i++)
{
if (user[i].Message == "Success")
{
resp = new HttpResponseMessage { Content = new ObjectContent(typeof(List<GetUserList>), user, GlobalConfiguration.Configuration.Formatters.JsonFormatter) };
}
else
{
resp = new HttpResponseMessage { Content = new StringContent("[{\"Message\":\"" + user[i].Message + "\"}]", System.Text.Encoding.UTF8, "application/json") };
}
}
The result should be like this:
{
"message": " Successful",
"supervisorlist": [
{
" userID ": "654",
" forename ": "John"
},
{
" userID ": "655",
" forename ": "Jack"
}
]
}
Aucun commentaire:
Enregistrer un commentaire