J'ai asp.net webservice avec json retournant des données, quand je l'appelle, il me renvoie des données dans json mais l'intègre dans xml.asp.net webservice renvoyant json embarqué en xml ...?
Que dois-je faire sur le côté serveur pour vous assurer que mon webservice retourne juste JSON?
Mon service .asmx est comme ci-dessous
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using System.Text;
using System.Collections;
using System.IO;
using System.Xml;
[WebMethod(Description = "DemoMethod to get Total.")]
public string GetTotal(string a, string b, string c)
{
List<Hashtable> objMyclass = new List<Hashtable>();
JSonOutPutProperties jsonProperty = new JSonOutPutProperties();
//
int total = Convert.ToInt32(a) + Convert.ToInt32(b) + Convert.ToInt32(c);
jsonProperty.Properties.Add("Total", total);
objMyclass.Add(jsonProperty.Properties);
//
JsonOutput objjson = new JsonOutput();
objjson.objectcount = objMyclass.Count;
objjson.objectname = "Total";
objjson.objectvalues = objMyclass;
//
JavaScriptSerializer js = new JavaScriptSerializer();
string strJSON = js.Serialize(objjson);
return strJSON;
}
Pourriez-vous clarifier votre question. Par exemple, quelle est la fin de l'URL? quel type de service (asmx, svc) utilisez-vous? Pouvez-vous poster une partie de la méthode à partir de votre webservice qui retourne le json? – surfmuggle
Salut troisfouronesixonethree, post mis à jour avec le code, avoir une idée de ce qui ne va pas –
High Deer pouvez-vous résoudre le problème en ajoutant la ligne '[ScriptMethod (UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]'? Quel est le résultat après avoir ajouté l'attribut? – surfmuggle