我有一个json字符串。我想使用字段名称从该字符串中获取值。请帮我搞定。这是我的json字符串格式。
[
{
"FLD_ID": 1,
"FLD_DATE": "17-02-2014 04:57:19 PM"
"FLD_USER_NAME": "DAFEDA",
"FLD_USER_EMAIL": "test@gmail.com",
"FLD_USER_PASS": "test"
}
]
答案 0 :(得分:3)
我不确定问题是什么,但
怎么样// assuming str is your JSON string
var obj = JSON.parse(str); // parse the string into an object
var firstObj = obj[0]; // get the first (and only) object out of the array
var fld_id = firstObj.FLD_ID; // you can access properties by name like this
var fld_date = firstObj['FLD_DATE']; // or like this
答案 1 :(得分:1)
您的JSON无效。我为你修好了。
[{"FLD_ID":1,"FLD_DATE":"17-02-2014 04:57:19 PM", "FLD_USER_NAME":"DAFEDA","FLD_USER_EMAIL":"test@gmail.com","FLD_USER_PASS":"test"}]
这是一个如何提醒FLD_ID
<script>
var json = [{"FLD_ID":1,"FLD_DATE":"17-02-2014 04:57:19 PM", "FLD_USER_NAME":"DAFEDA","FLD_USER_EMAIL":"test@gmail.com","FLD_USER_PASS":"test"}];
alert(json[0].FLD_ID);
</script>
顺便说一句,这是一个包含1个JSON对象的数组,这就是为什么你必须引用索引,在这种情况下为0。