高级javascript json解析
我有这个json文件:高级javascript json解析,javascript,arrays,json,parsing,Javascript,Arrays,Json,Parsing,我有这个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": "", "lang
{
"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"
}
]
}
}
]
}
我想在relations数组中的subject对象中的情感对象中获得情感类型“积极”,找到这个值的合适javascript代码是什么
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);