Javascript JSON布尔值似乎不起作用
我的web应用程序有点麻烦 我第一次使用JSON 其中json看起来像这样Javascript JSON布尔值似乎不起作用,javascript,json,Javascript,Json,我的web应用程序有点麻烦 我第一次使用JSON 其中json看起来像这样 { "Code":"310254351", "FirstName":null, "LastName":null, "NewUser":true } 我可以在我的HTML中看到“NewUser”bool非常完美。 不知何故,我无法得到的是在美国工作 $scope.checkForUserProfile = function () { $scope.getUserProfile(); if ($scop
{
"Code":"310254351",
"FirstName":null,
"LastName":null,
"NewUser":true
}
我可以在我的HTML中看到“NewUser”bool非常完美。
不知何故,我无法得到的是在美国工作
$scope.checkForUserProfile = function () {
$scope.getUserProfile();
if ($scope.userprofile.NewUser)
{
$scope.showWelcome = false;
$scope.showProfileNew = true;
}
else (!$scope.userprofile.NewUser)
{
$scope.showWelcome = true;
}
}
$scope.getUserProfile = function () {
$scope.loading = true;
$http.post('http://localhost:49165/Service1.svc/userprofile/get/').then(
function (response) {
$scope.userprofile = response.data;
}, function (errResponse) {
console.error('Error while getting user profile');
});
$scope.loading = false;
};
我是不是错过了一些演员
我尝试了几种方法,但这似乎不起作用
if ($scope.userprofile.NewUser = true){
//做点什么
}$scope.userprofile它似乎未定义。如果要执行此操作,请执行以下操作:
$scope.userprofile = $scope.getUserProfile();
否则就不能用这样的布尔值!拆下两个螺栓之间的钻头
因此,if变成:
您的代码在语法上不正确。检查浏览器的开发人员控制台,您将看到错误。$scope.userprofile实际填充了数据的位置、方式,尤其是何时…?能否在if语句之前添加一个console.log$scope.userprofile?仅供参考,这是在执行赋值,并且将始终通过条件。如果$scope.userprofile.NewUser=true{您需要一个比较===来代替。代码中有几个基本的Javascript错误,最明显的是:single=是一个赋值,而不是一个比较。与其根据猜测来回答,不如询问注释来澄清$scope.getUserProfile实际上设置了$scope.userprofile的值,因为它看起来可能是这样的。您可以ght@torazaburo,谢谢。虽然不是断言,但我已经明白了。
else (!$scope.userprofile.NewUser)
if ($scope.userprofile.NewUser)
{
$scope.showWelcome = false;
$scope.showProfileNew = true;
}
else
{
$scope.showWelcome = true;
}