-1

我有这个 json 文件:

{
    "status": "OK",
    "usage": "By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html",
    "url": "",
    "language": "english",
    "relations": [
        {
            "subject": {
                "text": "new single",
                "sentiment": {
                    "type": "positive",
                    "score": "0.179956"
                }
            },
            "action": {
                "text": "axed",
                "lemmatized": "axe",
                "verb": {
                    "text": "axe",
                    "tense": "past"
                }
            },

            "location": {
                "text": "in figure-hugging dress",
                "entities": [
                    {
                        "type": "City",
                        "text": "figure-hugging"
                    }
                ]
            }
        }
    ]
}

我想在关系数组中的主题对象内的情感对象中获取情感类型“正面”什么是正确的 JavaScript 代码来定位我尝试过的这个值

4

1 回答 1

0
var json = JSON.parse( ... your_loaded_json ... );

alert(json.relations[0].subject.sentiment.type);

请注意调用JSON.parse实际的 JSON。如果这只是 JavaScript 脚本中的一个对象,那么只需:

var json = { ... your_object ... }

alert(json.relations[0].subject.sentiment.type);
于 2013-09-21T20:36:56.237 回答