2011-10-12 6 views
0

웹 서비스에서 JSON을 가져 오려고 할 때 (상태 == "parsererror") "JSON 응답을 구문 분석 할 수 없음"을 의미합니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까.JSON 응답을 구문 분석 할 수 없습니다. JQUERY

MyService.asmx : .ASPX 페이지에서

[WebMethod] 
     public AssignmentInfo[] GetAssignmentInfo(int insId) 
     { 
      Proxies.ServiceRef.ServiceClient c = new Proxies.ServiceRef.ServiceClient(); 
      return c.GetAssignmentInfo(Id).ToArray(); 
     } 

JQuery와 구현입니다.

this.ServiceProxy = function (serviceUrl) { 
     var _I = this; 
    this.serviceUrl = serviceUrl; 
    this.isWcf = false; 
    this.timeout = 10000; 
    this.contentType = "application/json"; 

    this.invoke = function (method, params, callback, errorHandler) { 
    var jsonData = _I.isWcf ? JSON.stringifyWcf(params) : JSON.stringify(params); 

     // Service endpoint URL   
     var url = _I.serviceUrl + method; 

     $.ajax({ 
      url: url, 
      data: jsonData, 
      type: "POST", 
      contentType: _I.contentType, 
      timeout: _I.timeout, 
      dataType: "serviceproxy", // custom type to avoid double parse 
      dataFilter: function (jsonString, type) { 
       if (type == "serviceproxy") { 
        // Use json library so we can fix up dates   
        var res = JSON.parseWithDate(jsonString); 
        if (res && res.hasOwnProperty("d")) 
         res = res.d; 
        return res; 
       } 
       return jsonString; 
      }, 
      success: function (result) { 
       if (callback) 
        callback(result); 
      }, 
      error: function (xhr, status) { 
       var err = null; 
       if (xhr.readyState == 4) { 
        var res = xhr.responseText; 
        if (res && res.charAt(0) == '{' && status != "parsererror") 
         var err = JSON.parse(res); 
        if (!err) { 
         if (xhr.status && xhr.status != 200) 
          err = new CallbackException(xhr.status + " " + xhr.statusText); 
         else { 
          if (status == "parsererror") 
           status = "Unable to parse JSON response."; 
          else if (status == "timeout") 
           status = "Request timed out."; 
          else if (status == "error") 
           status = "Unknown error"; 
          err = new CallbackException("Callback Error: " + status); 
         } 
         err.detail = res; 
        } 
       } 
       if (!err) 
        err = new CallbackException("Callback Error: " + status); 

       if (errorHandler) 
        errorHandler(err, _I, xhr); 
      } 
     }); 
    } 
} 


var serviceUrl = "service/MyService.asmx/"; 
var proxy = new ServiceProxy(serviceUrl); 

function showAssignInfo() { 

      proxy.invoke("GetAssignmentInfo", 
      { insId: $("#IAssignmentId").val() }, 
      function (result) {    
        $.each(result, function (index) { 

        alert (this.ClaimId); 

       }); 
      }, onPageError); 

업데이트 1 :

JSON 응답 :

{"d":[{"__type":"Proxies.AFARServiceRef.AssignmentInfo","ExtensionData":{},"AssignDate":"\/Date(1317748587667)\/","AssignFileName":null,"ClaimId":"PA026195","ClaimantName":"Rachel Weiss","FirstContactDate":"\/Date(1302678000000)\/","FirstContactTime":{"Ticks":433800000000,"Days":0,"Hours":12,"Milliseconds":0,"Minutes":3,"Seconds":0,"TotalDays":0.50208333333333333,"TotalHours":12.049999999999999,"TotalMilliseconds":43380000,"TotalMinutes":723,"TotalSeconds":43380},"Id":5257,"InspectionDate":"\/Date(1302246000000)\/","StatusId":1,"SubmittedCount":5,"UploadedCount":9}]} 
+2

당신이 JSON 응답 – Rafay

답변

1

[WebMethod] 
[WebGet(ResponseFormat=WebMessageFormat.Json)] 
     public AssignmentInfo[] GetAssignmentInfo(int insId) 
     { 
      Proxies.ServiceRef.ServiceClient c = new Proxies.ServiceRef.ServiceClient(); 
      return c.GetAssignmentInfo(Id).ToArray(); 

     } 

enter image description here

+0

을 게시 할 수 있습니다하려고 난 당신이 반환을 의미하는 것 같아요 GetAssignmentInfo는 string입니다. 그렇다면 실제 데이터가 아닌 strJSON에 문자열 "System.Collections.Generic.List'1 [Proxies.ServiceRef.AssignmentInfo]"가 표시됩니다. – BumbleBee

+0

javascriptSerializer를 사용하지 않을 때 firebug에서 받고있는 json 응답을 게시 할 수 있습니까? 그것은 더 명확한 그림을 줄 것입니다. 나는 json이 잘 형성되어 있지 않다고 짐작하고있다. – Rafay

+0

도움이 될지도 모르는 편집을 보아라. – Rafay

관련 문제