我想将JSON响应数据转换为数组。使用json.stringify()
方法传递数据并以JSON格式获取响应。但我想将此响应转换为数组。我的代码是,
$.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);
},
});
此代码的回复:
{"LoginResult":{"ErrorCode":0,"StatusMessage":"Success","UserInfo":{"AccountID":"dfdgfgh","Description"
:"description Cabs","EmailID":"","Name":"","PhoneNumber":"","UserID":"asxdsvdgfbg"}}}
我想将userInfo
放入数组中。
请帮帮我。
答案 0 :(得分:1)
试试这个 的修改
var response = $.parseJSON(data);
var arr = response.LoginResult;
var userInfoArr = arr['UserInfo'];