0

I want to convert JSON response data into an array. Pass the data using json.stringify() method and get the response in JSON format. But I want to convert this response into an array. My code is,

 $.ajax({
url: "url/json/Login",
type: "POST",
data: JSON.stringify({
    accountID: "ymmsansdu",
    userID: "ymmascnuelas",
    password: "ymma23@123"
}),
contentType: "application/json; charset=utf-8",
success: function (data) {
    var response = JSON.stringify(data);
   alert(response);
},

});

The response of this code:

{"LoginResult":{"ErrorCode":0,"StatusMessage":"Success","UserInfo":{"AccountID":"dfdgfgh","Description"
:"description Cabs","EmailID":"","Name":"","PhoneNumber":"","UserID":"asxdsvdgfbg"}}}

I want to get userInfo into an array.

Please help me.

4
  • Pls read w3schools.com/json/json_eval.asp Commented Nov 19, 2015 at 4:54
  • I'm tried, but JSON.parse(response) is showing [object Object]. Commented Nov 19, 2015 at 4:59
  • @Arya The alert() is actually what's showing the "[object Object]" as it simply converts the value .toString(). And, that's the normal string form of an Object. This is in part why alert() isn't really the best tool for debugging. Try instead using console.log(response) and open the Console in your browser's developer tools to view the result. Commented Nov 19, 2015 at 5:22
  • Ok, Thank you so much :) Commented Nov 19, 2015 at 5:26

1 Answer 1

1

Try this EDIT

    var response = $.parseJSON(data);
    var arr = response.LoginResult;
    var userInfoArr = arr['UserInfo']; 
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.