访问JSON对象中的字段

时间:2014-06-27 04:05:01

标签: javascript json

在我的JSON对象中,我试图访问“pos”

中的“name”字段

我试过obj.tokens.pos.parent;              OBJ [0] .pos.parent;

如何访问此对象的父字段?

对象看起来像

[
 {
  "tokens": [
  {
   "text": "call",
   "normalised": "call",
   "end": true,
   "start": true,
   "pos": {
    "name": "infinitive verb",
    "example": "eat",
    "parent": "verb",
    "tense": "present",
    "tag": "VBP"
  },
  "pos_reason": "lexicon",
  "analysis": {
   "word": "call",
   "next": null,
   "last": null,
   "form": "infinitive",
   "tense": "present",
    "which": {
     "name": "infinitive verb",
     "example": "eat",
     "parent": "verb",
     "tense": "present",
     "tag": "VBP"
  },
  "negative": false
 }
 }
 ]
}
] 

4 个答案:

答案 0 :(得分:1)

这里的结果是数组格式,因此您需要访问像obj [0]

这样的数组元素
obj[0].tokens[0].pos.name

答案 1 :(得分:0)

尝试使用:obj[0].tokens[0].pos.name

答案 2 :(得分:0)

我不确定你想要什么,但你可以试试这个

obj[0]["tokens"][0]["pos"]["name"]

答案 3 :(得分:0)

这应该有效。

obj[0].tokens[0].pos.name