0

在我的控制器中,我正在调用网络服务

Metadata.Client.Service.Client returnClient = new Metadata.Client.Service.Client();

returnClient = client.UpdateClient(updateClient);

return Json(new { returnClient }, JsonRequestBehavior.AllowGet);   

在我的 .cshtml Ajax 调用中,如下所示

 $.ajax(
 {
     type: "GET",
     contentType: "application/json; charset=utf-8",
     url: '@Url.Action("UpdateRecord", "Client")',
     data: { "id": id, "name": clientName, "code": clientCode, "typeId": clientTypeId, "clientStatusCode": clientStatusCode },
     dataType: "json",
     beforeSend: function () {//alert(id);
     },
     error: function (request) {
     alert('error');    
     alert(request.responseText);
     },
     success: function (data) {
     alert('success');
     console.log(data);

     //var parsed = JSON.parse(data);
     //alert(parsed);
     //var k = JSON.stringify(data);
     //alert(parsed);

  }

我尝试了几种方法来提取数据。在console.log它显示如下

[09:27:07.989] ({returnClient:{ExtensionData:{}, ClientCode:"C09091", ClientId:39, ClientName:"Test1", ClientStatus:[{ExtensionData:{}, StatusCode:{ExtensionData:{}, Name:"Active", StatusCodeId:5}, StatusType:{ExtensionData:{}, Name:"OE", StatusTypeId:1}}], ClientType:{ExtensionData:{}, ClientTypeId:7, ClientTypeName:"FDFD"}}})

请任何人都可以帮助提取这些数据

IE,ClientName, ClientCode, ClientId, ClientStatus.StatusCode, ClientStatus.Name, ClientStatus.StatusCodeId, StatusType.Name

4

2 回答 2

1
success: function (data) {
    var ccode = data.returnClient.ClientCode;
    var cid = data.returnClient.ClientId;
    var cname = data.returnClient.ClientName;
    var ctypeid = data.returnClient.ClientType.ClientTypeId;
    var ctypename = data.returnClient.ClientType.ClientTypeName;

    for (var i = 0; i < data.returnClient.ClientStatus.length; i++) {
      var codeName = data.returnClient.ClientStatus[i].StatusCode.Name;
      var codeId = data.returnClient.ClientStatus[i].StatusCode.StatusCodeId;
      var typeName = data.returnClient.ClientStatus[i].StatusType.Name;
      var typeId = data.returnClient.ClientStatus[i].StatusType.StatusTypeId;
    }
}
于 2013-02-18T09:51:33.377 回答
1

您可以尝试以下操作:

var jsonData = eval("(" + data + ")");

这将返回 JSON 对象。然后您可以使用点 (.) 运算符或使用 [ ] 从此 JSON 对象中检索数据

于 2013-02-18T09:54:14.547 回答