我有这个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代码我试过了
答案 0 :(得分:0)
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);