Greetings i want to call a web api that returns a json string from From Controller and i want to map it on a class so i can save the data on the database.But i dont understand how to map each data on the json with the class. I only get the message that is succeed. my code is:
public ActionResult API()
{
var client = new WebClient();
var text = client.DownloadString("https://www.example.com/api/all-users?name=user%20&pass=password");
wclients wclients = JsonConvert.DeserializeObject<wclients>(text);
if (wclients.message == "success")
{
ViewBag.name = ("name = " + wclients.name);
}
return View();
}
my view is this:
@foreach (var item in ViewBag.name) {
<tr>
<td>
@item
</td>
</tr>
}
The Response from web api is:
{"status":true,"message":"success","data":[{"name":"test test","email":"[email protected]","phone":"1234567890","affiliated_id":null,"account":{"real":[{"login":"1001175","pass":"4pJccK8AUWw8"},{"login":"3001180","pass":"4AeCqasw7jX2"},{"login":"3001182","pass":"fS2tf6Gsej7C"}]
jscode.