当我运行此函数时,我得到了一个JSON对象,如图所示 我只想显示一个选定的参数,比如用户名。
[displaying json object on running this function][1]
$scope.signUp = function () {
$http({
method: "post",
dataType:'json',
url: "http://192.168.0.60/api/Customer/CustomerLoginService",
crossDomain : true,
data: {
'username': $scope.username,
'password': $scope.password,
'entrytoken': $scope.entrytoken
},
headers: { 'Accept':' text/plain','Content-Type': 'application/json' }
}).then(function success(data) {
alert("success function");
var obj=JSON.stringify(data);
alert(obj);
});
如何显示单个参数。
答案 0 :(得分:1)
then(function success(data) {
alert(data.data.username);
});
答案 1 :(得分:0)
alert(obj.data.username);
对象属性可以像任何普通对象一样进行访问。 但是在将来,没有必要对返回进行字符串化。
答案 2 :(得分:0)
headers: { 'Accept':' text/plain','Content-Type': 'application/json' }
}).then(function success(data) {
alert("success function");
// var obj=JSON.stringify(data);
console.log('DATA=',data);
这将允许您检查数据返回中是否存在用户名作为响应。打开浏览器控制台以查看数据。请使用谷歌浏览器