I'm new to web, I'm trying to return a json but it comes with bars like this:
{\"NomeUsuario\":\"TESTE\",\"TelefoneUsuario\":\"1111111111\"}
How do I make it look like this:
{"NomeUsuario":"TESTE","TelefoneUsuario":"1111111111"}
I have the class person:
[DataContract]
public class Pessoa
{
[DataMember]
public string Nome { get; set; }
[DataMember]
public string TelefoneUsuario { get; set; }
}
Method
public string FiltradoPorPessoa(string Nome, string Variavel)
{
DataTable Dtconsulta = new DataTable();
Pessoa retorno = null;
Sql = " SELECT NomeUsuario, TelefoneUsuario";
Sql += " FROM Cadastro.DTUsuario";
Sql += " WHERE NomeUsuario = '" + Nome.ToUpper() + "' AND SenhaUsuario = '" + GeraHash(Variavel.ToUpper()) + "'";
DataTable dataTable = new DataTable();
SqlCommand cmd = new SqlCommand(Sql, conn);
conn.Open();
adapter = new SqlDataAdapter(cmd);
adapter.Fill(dataTable);
if (dataTable.Rows.Count > 0)
{
Pessoa p = new Pessoa();
DataTableReader DtConsultaReader = dataTable.CreateDataReader();
while (DtConsultaReader.Read())
{
p.Nome = DtConsultaReader["NomeUsuario"].ToString();
p.TelefoneUsuario = DtConsultaReader["TelefoneUsuario"].ToString();
}
DtConsultaReader.Close();
conn.Close();
var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(p);
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Pessoa));
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
retorno = (Pessoa)ser.ReadObject(ms);
}
return retorno;
}
And a method that returns a datatable, copy that to a datareader, what am I doing wrong, I can not return the string?
Can not implicitly convert type 'test15_04.Person' to 'string' in this way {"UserName": "TEST", "UserPhone": "1111111111"}