0

大家好,当从 web 服务顶部标签返回 json 数据时,请让我知道如何删除 web 服务中的顶部 xml 标签,
如果有人遇到这个问题,请告诉我

我用下面的方法读

var obj = 新列表();

    //MakesInfo objMakes = new MakesInfo();
    MakesBL objMakesBL = new MakesBL();

    if (Session["Makes"] == null)
    {
        obj = (List<MakesInfo>)objMakesBL.GetMakes();
        Session["Makes"] = obj;
    }
    else
    {
        obj = (List<MakesInfo>)Session["Makes"];
    }
    StringBuilder str = new StringBuilder();


    //var oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
    //string sJSON = oSerializer.Serialize(obj);

    //return sJSON;

    //yourobject is your actula object (may be collection) you want to serialize to json
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<MakesInfo>));


    //create a memory stream
    MemoryStream ms = new MemoryStream();
    //serialize the object to memory stream
    serializer.WriteObject(ms, obj);
    //convert the serizlized object to string
    string jsonString = Encoding.Default.GetString(ms.ToArray());
    //close the memory stream
    ms.Close();
    return jsonString;
4

1 回答 1

0

使用 WCF 只返回列表 json 对象数据返回

于 2012-10-09T13:19:17.220 回答