1
I generated a webservice using visual studio 2013, mysql using database first, until well, but when I put to generate in json, the answer is as follows:
string xmlns="http://digits.com.br/"> {"PAR_ID_23":2,"PAR_RAZAO_SOCIAL_23":"GILVAN JOAO DA SILVA","PAR_SENHA_MOBILE_23":"12","PAR_MOBILE_23":null}
But when I go I wish the return was:
{"Android":[{"PAR_ID_23":2,"PAR_RAZAO_SOCIAL_23":"GILVAN JOAO DA SILVA","PAR_SENHA_MOBILE_23":"12","PAR_MOBILE_23":null}]}>
I found this example:
[WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void HelloWorld() { // return "Hello World"; JavaScriptSerializer js = new JavaScriptSerializer(); Context.Response.Clear(); Context.Response.ContentType = "application/json"; RegSuMsg data = new RegSuMsg(); data.Message = "Hello world !"; Context.Response.Write(js.Serialize(data)); } }
public class RegSuMsg
{
public String Message;
}
Which works but I can’t adapt it to my function because it uses classes:
[WebMethod]
public string ConsultarParceirosTodos()
{
try
{
NegLogin negLogin = new NegLogin();
List<parceiro_23> colecao = new List<parceiro_23>();
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
string json = string.Empty;
colecao.AddRange(negLogin.ConsultarParceiroTodos());
json = jsSerializer.Serialize(colecao);
return json;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
I have tried to adapt it in various ways but the return is always not compatible, if I take the return I leave Context.Response.Write(js.Serialize(data)), also from the error in the execution.
Solved your doubt?
– durtto