How to get JSON response from a 3.5 asmx web service

后端 未结 4 1414
梦谈多话
梦谈多话 2020-11-27 07:03

I have the following method:

using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using         


        
4条回答
  •  感动是毒
    2020-11-27 07:19

    Sometimes we don't have access to make changes in WebService definition and sometimes we should not make changes in WebServices! so the best solution is set contentType="application/json; charset=..." in your request. just this!

    For example you can use below code (if you are using jquery) instead of changing somethings in WebService:

    $.ajax({
            type: "POST",
            url: '/ServiceName.asmx/WebMethodName',
            date: {},
            contentType: "application/json; charset=utf-8",
            success: function (data) {                
                    // Some code;
    
            }
        });
    

    Then you can use JSON.parse(data.d) to access json structure of your data.

提交回复
热议问题