3

I've been at this for a while and can't seem to nail it down, your help is much appreciated.

Challenge: Unable to identify how to properly use JQUERY to parse the following JSON (String?) response from the server:

{"d":"{\"NewDataSet\":{\"Table\":{\"EMPLOYEE_NO\":\"3605\",\"NAME\":\"Last, First\",\"STAFF\":\"CSR\",\"USERNAME\":\"lis\",\"PIN\":\"somepassword\"}}}"}

Tried: Many things, such as...

var dtObj = jQuery.parseJSON(data);
$.each(dtObj, function (i, val) {
.. do some stuff
});

Requirement: Need to get the EMPLOYEE_NO, NAME, STAFF, USERNAME, AND PING values.

Thanks!

2 Answers 2

1

Your JSON id nested, so you'll have to parse twice and the object that holds the data you want is some levels deep.

var Obj1 = jQuery.parseJSON(data);
var Obj2 = jQuery.parseJSON(Obj1.d);
var dtObj = Obj2.NewDataSet.Table;
// now you can use dtObj to access EMPLOYEE_NO, NAME, STAFF, USERNAME, AND PING properties.

jsFiddle

Sign up to request clarification or add additional context in comments.

Comments

0

First make sure, your json is valid. Use this tool http://jsonlint.com/

var data={
    "d": {
        "NewDataSet": {
            "Table": {
                "EMPLOYEE_NO": "3605",
                "NAME": "Last,First",
                "STAFF": "CSR",
                "USERNAME": "lis",
                "PIN": "somepassword"
            }
        }
    }
};
alert(data.d.NewDataSet.Table.NAME);

http://jsfiddle.net/tariqulazam/rBfLw/

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.