Arya
Arya

Reputation: 504

convert json response data into an array

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.

Upvotes: 0

Views: 2513

Answers (1)

A J
A J

Reputation: 4024

Try this EDIT

    var response = $.parseJSON(data);
    var arr = response.LoginResult;
    var userInfoArr = arr['UserInfo']; 

Upvotes: 1

Related Questions