【问题标题】:advanced javascript json parsing [duplicate]高级javascript json解析[重复]
【发布时间】:2013-09-21 20:19:26
【问题描述】:

我有这个 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 代码是什么

【问题讨论】:

    标签: javascript arrays json parsing


    【解决方案1】:
    var json = JSON.parse( ... your_loaded_json ... );
    
    alert(json.relations[0].subject.sentiment.type);
    

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

    var json = { ... your_object ... }
    
    alert(json.relations[0].subject.sentiment.type);
    

    【讨论】:

      猜你喜欢
      • 2013-02-02
      • 2012-04-10
      • 2017-01-09
      • 2013-08-23
      • 1970-01-01
      • 2016-02-01
      • 2021-11-16
      • 2021-02-18
      • 1970-01-01
      相关资源
      最近更新 更多