使用空属性名称

时间:2015-08-04 05:28:33

标签: javascript json

如果我有下面的json对象...我怎么能访问字符串“密码必须...”。

ModelState中的“”属性名称让我感到困惑。

谢谢!

{
    "Message": "The request is invalid.",
    "ModelState": {
        "": [
            "Passwords must have at least one non letter or digit character. Passwords must have at least one uppercase ('A'-'Z')."
        ]
    }
}

5 个答案:

答案 0 :(得分:1)

喜欢这样



var data = {
    "Message": "The request is invalid.",
    "ModelState": {
        "": [
            "Passwords must have at least one non letter or digit character. Passwords must have at least one uppercase ('A'-'Z')."
        ]
    }
};

console.log(data.ModelState['']);




答案 1 :(得分:0)

var a = {
    "Message": "The request is invalid.",
    "ModelState": {
        "": [
            "Passwords must have at least one non letter or digit character. Passwords must have at least one uppercase ('A'-'Z')."
        ]
    }
}

var yourAnswer = a.ModelState[""];```

答案 2 :(得分:0)

你可以这样做:

var somedata = {
    "Message": "The request is invalid.",
    "ModelState": {
        "": [
            "Passwords must have at least one non letter or digit character. Passwords must have at least one uppercase ('A'-'Z')."
        ]
    }
};
console.log(somedata["ModelState"][""]);

答案 3 :(得分:0)

var my_dict = {
    "Message": "The request is invalid.",
    "ModelState": {
        "": [
            "Passwords must have at least one non letter or digit character. Passwords must have at least one uppercase ('A'-'Z')."
        ]
    }
}
var my_string = my_dict['ModelState'][''][0]

这对我有用

答案 4 :(得分:0)

var a={
    "Message": "The request is invalid.",
"ModelState": {
    "": [
        "Passwords must have at least one non letter or digit character. Passwords must have at least one uppercase ('A'-'Z')."
    ]
}
};
console.log(a.ModelState[""]);

screenshot