需要帮助从JSON代码中检索信息

时间:2014-01-04 17:15:54

标签: json

最近我尝试了一个名为 medical Dictionary 的API,它以XML格式输出。我重新编码并创建了以下批量代码。 我需要知道如何从以下JSON代码中检索“携带营养和氧气的脊椎动物的心脏,动脉,毛细血管和静脉中循环的液体,并从身体的各个部位带走废物”。

result ={
"@attributes": {
    "version": "1.0"
},
"entry": [
    {
        "@attributes": {
            "id": "blood"
        },
        "hw": "blood",
        "pr": "ˈbləd",
        "sound": {
            "wav": "blood001.wav",
            "wpr": "!blud"
        },
        "fl": "noun",
        "lb": "often attrib",
        "def": {
            "sensb": [
                {
                    "sens": {
                        "sn": "1",
                        "dt": "the fluid that circulates in the heart, arteries, capillaries, and veins of a vertebrate animal carrying nourishment and oxygen to and bringing away waste products from all parts of the body"
                    }
                },
                {
                    "sens": {
                        "sn": "2",
                        "dt": "a fluid of an invertebrate comparable to blood"
                    }
                },
                {
                    "sens": {
                        "sn": "3",
                        "dt": "blood regarded in medieval physiology as one of the four humors and believed to be the seat of the emotions"
                    }
                },
                {
                    "sens": {
                        "sn": "4",
                        "dt": "descent from parents of recognized breed or pedigree"
                    }
                }
            ]
        }
    },
    {
        "@attributes": {
            "id": "blood bank"
        },
        "hw": "blood bank",
        "fl": "noun",
        "def": {
            "sensb": {
                "sens": {
                    "dt": [
                        "a place for storage of or an institution storing blood or plasma",
                        "blood so stored"
                    ],
                    "sd": "also"
                }
            }
        },
        "uro": {
            "ure": "blood bank·er",
            "pr": "-ˈbaŋ-kər",
            "sound": {
                "wav": "banker01.wav",
                "wpr": "!baN-kur"
            },
            "fl": "noun"
        }
    },
    {
        "@attributes": {
            "id": "blood banking"
        },
        "hw": "blood bank·ing",
        "pr": "-ˈbaŋ-kiŋ",
        "sound": {
            "wav": "blood01m.wav",
            "wpr": "!blud-!baN-kiN"
        },
        "fl": "noun",
        "def": {
            "sensb": {
                "sens": {
                    "dt": "the activity of administering or working in a blood bank"
                }
            }
        }
    },
    {
        "@attributes": {
            "id": "blood{ndash}borne"
        },
        "hw": "blood–borne",
        "pr": "-ˌbȯrn",
        "sound": {
            "wav": "blood06m.wav"
        },
        "fl": "adjective",
        "def": {
            "sensb": {
                "sens": {
                    "dt": "carried or transmitted by the blood "
                }
            }
        }
    },
    {
        "@attributes": {
            "id": "blood{ndash}brain barrier"
        },
        "hw": "blood–brain barrier",
        "fl": "noun",
        "def": {
            "sensb": {
                "sens": {
                    "dt": "a naturally occurring barrier created by the modification of brain capillaries (as by reduction in fenestration and formation of tight cell-to-cell contacts) that prevents many substances from leaving the blood and crossing the capillary walls into the brain tissues "
                }
            }
        }
    },
    {
        "@attributes": {
            "id": "blood cell"
        },
        "hw": "blood cell",
        "fl": "noun",
        "def": {
            "sensb": {
                "sens": {
                    "dt": "a cell or platelet normally present in blood "
                }
            }
        }
    },
    {
        "@attributes": {
            "id": "blood clot"
        },
        "hw": "blood clot",
        "fl": "noun",
        "def": {
            "sensb": {
                "sens": {
                    "dt": {
                        "sx": "clot"
                    }
                }
            }
        }
    },
    {
        "@attributes": {
            "id": "blood count"
        },
        "hw": "blood count",
        "fl": "noun",
        "def": {
            "sensb": {
                "sens": {
                    "dt": [
                        "the determination of the blood cells in a definite volume of blood",
                        "the number of cells so determined "
                    ],
                    "sd": "also"
                }
            }
        }
    },
    {
        "@attributes": {
            "id": "blood doping"
        },
        "hw": "blood doping",
        "fl": "noun",
        "def": {
            "sensb": {
                "sens": {
                    "dt": "a technique for temporarily improving athletic performance in which oxygen-carrying red blood cells previously withdrawn from an athlete are injected back just before an event "
                }
            }
        }
    },
    {
        "@attributes": {
            "id": "blood dust"
        },
        "hw": "blood dust",
        "fl": "noun",
        "def": {
            "sensb": {
                "sens": {
                    "dt": {
                        "sx": "HEMOCONIA"
                    }
                }
            }
        }
    }
]

};

1 个答案:

答案 0 :(得分:0)

如果您想通过

进行迭代,可以像这样访问它
for (var i = 0; i < result.entry.length; i++) {
    for(var j =0; j < result.entry[i].def.sensb.length; j++) {
        if (result.entry[i].def.sensb[j].sens.dt === 'the fluid that circulates in the heart, arteries, capillaries, and veins of a vertebrate animal carrying nourishment and oxygen to and bringing away waste products from all parts of the body') {
            // matches your description
            break;
        }
    }
}

或者如果你想要第一个,你可以通过

访问它
result.entry[0].def.sensb[0].sens.dt

检查http://jsfiddle.net/raunakkathuria/8VQ7L/