I got the below JSON.Stringify data from ajax call to c# code. I am trying to loop through each country like. But I am unable to make countryList as List or array from resultant string from ajax call. String returned to controller is ["Germany","Brazil","United States"] while debugging but it is showing with reverse slashes and It fails reading in loop.
foreach (var cntry in countryList){
//my code
}
I tried the below
Try parsing the JSON first. Here's how:
foreach (var cntry in Newtonsoft.Json.JsonConvert.DeserializeObject<string[]>(countryList))
{
//my code
}
You need to NuGet "Newtonsoft.Json" to get this to work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.