Newtonsoft.Json.JsonSerializationException was unhandled by user code
What am I missing here? Why do I get this exception?
Newtonsoft.Json.JsonSerializationException was unhandled by user code,
Error converting value
"[{"username":"someone","computername":"computer1","PID":"1234"}]" to type
'System.Collections.Generic.List`1[WebApplication4.PInfo]'. Path '', line
1, position 95.
The code is below, very simple class, very simple content, but a nasty
error =(
public class PInfo
{
public string username { get; set; }
public string computername { get; set; }
public string PID { get; set; }
}
string s =
"\"[{\\\"username\\\":\\\"someone\\\",\\\"computername\\\":\\\"computer1\\\",\\\"PID\\\":\\\"1234\\\"}]\"";
var z = JsonConvert.DeserializeObject<List<PInfo>>(s);
Hi friend,
ReplyDeleteUse this below code will work.
using Newtonsoft.Json.Linq;
string finalData = JToken.Parse(s).ToString();
var z = JsonConvert.DeserializeObject>(finalData);