JSON层次结构,如何获取元素?

时间:2012-08-12 11:58:42

标签: javascript jquery json

$("#loginsubmit").live("click", function() {
    var request = new Request();
    request.service = "http://88.80.223.163:8080/lumiin-service/lumiin/control/eventmap/1" ;
    RequestHandler(request,displayData);
});  

function displayData(data) {
    //alert(data.contents.ownerId);
    var cont =  data.contents;
    $("#mono").html(''+cont.id);
}

我正在使用上面的代码段来获取ID,这很正常......如何获得firstName

对象

{
  "id": 1,
  "eventId": {
    "URL": "web",
    "location": "web",
    "url": "web",
    "id": 54,
    "type": {
      "name": "Meeting",
      "id": 1,
      "isDeleted": "N",
      "description": "Meeting"
    },
    "abteilung": {
      "id": 165,
      "code": "web123",
      "isDeleted": null,
      "domainId": 0,
      "parentId": 164,
      "description": null
    },
    "eventName": "Tanvi",
    "place": "web",
    "startDate": 1335830400000,
    "endDate": 1337558400000,
    "prospectId": null,
    "person": "web",
    "isDeleted": "N",
    "countryId": {
      "name": "CH",
      "id": 1,
      "isDeleted": "N",
      "description": "Switzerland"
    },
    "followUp": null,
    "budget": 0,
    "description": "web"
  },
  "ownerId": {
    "id": 67,
    "firstName": "web123",
    "localOrg": null,
    "industryTypeId": null,
    "memeber": false,
    "profileType": "Manager",
    "emailId": "web123",
    "abteilung": {
      "id": 165,
      "code": "web123",
      "isDeleted": null,
      "domainId": 0,
      "parentId": 164,
      "description": null
    },
    "userCode": "web123",
    "authenticatedAccess": -1,
    "uuid": null,
    "lastName": "web123",
    "isDeleted": "N",
    "passWord": "web123",
    "fullName": "web123,web123",
    "status": 0
  },
  "prospectId": {
    "id": 303,
    "firstName": "web123",
    "emailId": "web123@gg.com",
    "ownerId": {
      "id": 67,
      "firstName": "web123",
      "localOrg": null,
      "industryTypeId": null,
      "memeber": false,
      "profileType": "Manager",
      "emailId": "web123",
      "abteilung": {
        "id": 165,
        "code": "web123",
        "isDeleted": null,
        "domainId": 0,
        "parentId": 164,
        "description": null
      },
      "userCode": "web123",
      "authenticatedAccess": -1,
      "uuid": null,
      "lastName": "web123",
      "isDeleted": "N",
      "passWord": "web123",
      "fullName": "web123,web123",
      "status": 0
    },
    "abteilung": {
      "id": 165,
      "code": "web123",
      "isDeleted": null,
      "domainId": 0,
      "parentId": 164,
      "description": null
    },
    "startDate": 1335744000000,
    "endDate": 1337904000000,
    "statusId": {
      "name": "New",
      "id": 1,
      "isDeleted": "N",
      "description": "New"
    },
    "company": "company",
    "lastName": "web123",
    "isDeleted": "N",
    "yearofBirth": null,
    "annualRevenue": 0,
    "nationalityId": {
      "name": "CH",
      "id": 1,
      "isDeleted": "N",
      "description": "Switzerland"
    },
    "titleId": {
      "name": "Mr",
      "id": 1,
      "isDeleted": "N",
      "description": "Mr"
    },
    "maritalstatusId": null,
    "residencyId": null,
    "languageId": null,
    "priorityId": {
      "name": "Low",
      "id": 1,
      "isDeleted": "N",
      "description": "Low"
    },
    "genderId": {
      "name": "Male",
      "id": 1,
      "isDeleted": "N",
      "description": "Male"
    }
  },
  "isDeleted": "N"
}

1 个答案:

答案 0 :(得分:2)

firstNameprospectId对象的属性,您可以通过这种方式阅读它:

var firstName = data.prospectId.firstName;
var lastName = data.prospectId.lastName;

Fiddle