1

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?

3
  • 4
    Can you please provide more context? If the variable response is set to that data structure, response.data.detections[0][0].language returns "en" Commented Sep 13, 2011 at 1:26
  • It works for me, if i access it in the format you have provided. Commented Sep 13, 2011 at 1:28
  • jsfiddle.net/EfJBN works for me Commented Sep 13, 2011 at 1:35

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.