简体   繁体   中英

Accessing a JSON object that contains a nested array using jQuery

I made an API call (google translate) and it returns the following:

{
 "data": {
  "detections": [
   [
    {
     "language": "en",
     "isReliable": false,
     "confidence": 0.051902372
    }
   ]
  ]
 }
}

I want to access the "language" value using javascript (using the jQuery ajax function). 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM