Hello friends,
here am facing little bit problem while deserializing json string to list
json string : Result of restful service
"\"[{\\\"UName\\\":\\\"prasad\\\",\\\"LastName\\\":\\\"k\\\",\\\"FirstName\\\":\\\"sai\\\"}]\""
and i want to convert this json string to list of "_TempUser" class
my list :
public class _TempUser
{
public string UName
{
get;
set;
}
public string LastName
{
get;
set;
}
public string FirstName
{
get;
set;
}
}
Error is
Error converting value "[{"UName":"prasad","LastName":"k","FirstName":"sai"}]" to type 'System.Collections.Generic.List`1[loginServices.Login_Service+_TempUser]'. Path '', line 1, position 70.
code in my restful service
List<_TempUser> List = new List<_TempUser>();
_TempUser ud = new _TempUser();
ud.UName = "prasad";
ud.FirstName = "sai";
ud.LastName = "k";
List.Add(ud);
string json = JsonConvert.SerializeObject(List);
return json;
code : for calling restful service
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://IpAddress:Post/Login/RestServiceName.svc/RestMethoName");
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json =JsonConvert.SerializeObject(Req);
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
string result = streamReader.ReadToEnd();
List<_TempUser> List = new List<_TempUser>();
List = JsonConvert.DeserializeObject<List<_TempUser>>result
}
}
any modifications or suggestions plz?