I have passed Json object though Postman. And I have no idea how can I loop this with .NetCore 1.1 Web Service.
Json Object passed by Postman:
{
[
{"id":"1","name":"Peter"}
,
{"id":"2","name":"Mary"}
]
}
.net core 1.1 coding:
[HttpPut]
[Route("all")]
public IActionResult UpdateName([FromBody] dynamic JSON){
var RootObjects = JsonConvert.DeserializeObject<List<RootObject>>(JSON);
foreach (var x in RootObjects){
// do something here...
}
}
RootObjects:
private class RootObject
{
public string id { get; set; }
public string name { get; set; }
}
And I get error below:
System.ArgumentNullException: Value cannot be null.\r\nParameter name: value\r\n at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)\r\n at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)\r\n at CallSite.Target(Closure , CallSite , Type , Object )\r\n