[英]Accessing a JSON object that contains a nested array using jQuery
I made an API call (google translate) and it returns the following: 我进行了API调用(谷歌翻译),它返回以下内容:
{
"data": {
"detections": [
[
{
"language": "en",
"isReliable": false,
"confidence": 0.051902372
}
]
]
}
}
I want to access the "language" value using javascript (using the jQuery ajax function). 我想使用javascript(使用jQuery ajax函数)访问“语言”值。 I tried something like:
我尝试了类似的东西:
response.data.detections[0][0].language
but that does not work. 但这不起作用。 Help?
救命?
We really do need more information but if I had to guess blindly I would guess that response actually contains the following string: 我们确实确实需要更多信息,但是如果我不得不盲目猜测,我可能会认为响应实际上包含以下字符串:
'{
"data": {
"detections": [
[
{
"language": "en",
"isReliable": false,
"confidence": 0.051902372
}
]
]
}
}'
If that is the case you could try something like $.parseJSON(response).data.detections[0][0].language 如果是这种情况,您可以尝试类似$ .parseJSON(response).data.detections [0] [0] .language的操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.