V.V
V.V

Reputation: 883

Undefined value in JSON

I get the Json by using the post Method,

                    $.post('urlhere', function (data) {
                        alert(data.Experience)
                    });

If I trying to get one element from the JSON Response like alert(data.Experience).But It will show "Undefined".How to get the particular node from the following Json?

Get the Response like,

[
    {
        "Name": null,
        "EmployeeId": 0,
        "Email": null,
        "UserName": null,
        "Password": null,
        "JobTitle": null,
        "JobID": null,
        "SkillsRequired": "Struct",
        "Experience": "2",
        "Description": null,
        "listval": null,
        "Status": null,
        "JobLocation": null,
        "JobPostedDate": "/Date(-62135596800000)/",
        "AssignJobID": null,
        "AssignJobTitle": null,
        "AssignJobHr": null,
        "AssignDateofInterview": "/Date(-62135596800000)/",
        "AssignDescription": null
    }
]

Upvotes: 5

Views: 8885

Answers (4)

Anshu Bhattarai
Anshu Bhattarai

Reputation: 73

It looks like you are receiving a json array. First get the required object from array and then retrieve Experience. Try:

//index specifies the index of object inside json array
var index=0;  
alert(data[index].Experience);

Upvotes: 2

Yerko Aguirre
Yerko Aguirre

Reputation: 33

I tried this in chrome dev tools.

data = [
    {
        "Name": null,
        "EmployeeId": 0,
        "Email": null,
        "UserName": null,
        "Password": null,
        "JobTitle": null,
        "JobID": null,
        "SkillsRequired": "Struct",
        "Experience": "2",
        "Description": null,
        "listval": null,
        "Status": null,
        "JobLocation": null,
        "JobPostedDate": "/Date(-62135596800000)/",
        "AssignJobID": null,
        "AssignJobTitle": null,
        "AssignJobHr": null,
        "AssignDateofInterview": "/Date(-62135596800000)/",
        "AssignDescription": null
    }
]

and is working with this:

data[0].Experience

Upvotes: 1

Sridhar R
Sridhar R

Reputation: 20408

Try with

JSON Array 0th Object Has Experience.SO Acces Like Below

alert(data[0].Experience)

DEMO

Upvotes: 2

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

First make sure that the JSON that you are receiving is a parsed form of json or a string, If it is a string parse it before accessing values from it like JSON.parse(data). And the second thing is the data that you are receiving is a kind of array, so you must need to specify the index to access the values inside it meaning the JSON.

Try,

alert(data[0].Experience);

Upvotes: 5

Related Questions