I created a webservice using visual studio 2013, mysql using database first, until then okay, but when I put it to generate in json, the answer stays 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 want the return to be:
{"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;
}
That works however I can not 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 tried to adapt it in several ways but the return is always imcompatable, if I take the return I leave the Context.Response.Write (js.Serialize (date)), also of the error in the execution.