0

I'am having problem in accessing json array elements. Below is the response when i send data using POST method in ajax. How can i access only middlename, result from response. Please help me

{
"class": "MyF",
 "result": {
 "authToken": "abcd",
 "authTokens": [
 {
   "name": "ABC",
    "class": "AuthToken"
 }
],
"class": "User",
"middlename": "xyz",
"lastname": "abc",
},
"result": "1234"
}
1
  • That's a correct json array? Commented Jun 26, 2012 at 11:16

3 Answers 3

4

If you're using jQuery you could just do

var obj = jQuery.parseJSON('jsonstring');

Then you could get middlename by

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

Comments

1

Use jQuery.parseJSON

In you case

var obj = jQuery.parseJSON('{
"class": "MyF",
 "result": {
 "authToken": "abcd",
 "authTokens": [
 {
   "name": "ABC",
    "class": "AuthToken"
 }
],
"class": "User",
"middlename": "xyz",
"lastname": "abc",
},
"result": "1234"
}');

Comments

0
$.post('ajax/test.html', function(data) {
    var parsedData = $.parseJSON(data);
});

This create object JSON, and you can traversing on him.

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.