0

I am trying to retrieve the value of the JSON data and assign it to the JSON variable in the Angular like this:

$scope.bulkCreateRequest = function (jsonData) {
        var data = {
            "SERVICEREASON": jsonData.ServiceReason,
            "SITE": jsonData.Site,
            "FACILITY": jsonData.Location,
         };
}

When I debug the application though the jsonData has content, it says defined for SERVICEREASON,SITE,FACILITY like below in Local

enter image description here

enter image description here

I am not sure what I am missing here.

1 Answer 1

2

jsonData seems to be an array, so jsonData[0]["ServiceReason"] should work, also first verify if its a string, if it is then you will have to first convert it to array of object like jsonData = JSON.parse(jsonData)

so final code might look like -

$scope.bulkCreateRequest = function (jsonData) {
    jsonData = JSON.parse(jsonData);
    var data = {
        "SERVICEREASON": jsonData[0]["ServiceReason"], // this will also work
        "SITE": jsonData[0].Site,
        "FACILITY": jsonData[0].Location,
    };
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.