2017-05-31 83 views
1

我有一个Json文件和JavaScript文件中的ajax调用。尝试使用Hello World asmx文件模板编写正确的webservice方法。为了在网站上显示/返回/阅读json数据,我应该在方法中写什么?使用Webservice调用外部Json文件使用Ajax调用

$(document).ready(function() { 
$.ajax({ 
    type: "POST", 
    contentType: "application/json; charset=utf-8", 
    url: "http://localhost:56537/WebService.asmx/HelloWorld", 
    data: "{}", 
    dataType: "json", 
    success: function (Result) { 
     debugger; 
     Result = Result.d; 
     var data = []; 
var dataResource = response 
+0

,您仍然可以使一个ASMX Web服务,但它确实是不支持通过Microsoft多更多。更好地使用WCF服务应用程序。您可以使用DataContractJsonSerilizer。 –

+0

感谢您的提示! –

回答

0

那是对我工作的解决方案:

[的WebMethod]

public string HelloWorld() { 

    using (StreamReader r = new StreamReader(@"C:\Users\data.json")) 
    { 

     string json = r.ReadToEnd(); 

     return json; 

    }