ethanenglish
ethanenglish

Reputation: 1327

Extracting JSON Elements with JS

This is my JSON:

   "url": "http://www.myurl.com/",
    "language": "english",
    "concepts": [
        {
            "text": "world news",
            "relevance": "0.964403",
            "dbpedia": "http://dbpedia.org/resource/John_McCain",
            "freebase": "http://rdf.freebase.com/ns/guid.9202a8c04000641f800000000005767a"

I can retrieve the URL with this:

return object.url;

I would like to retrieve text:

return object.concepts[]

I feel like this is a simple solution but any help would be much appreciated.

Upvotes: 0

Views: 1381

Answers (2)

Tariqulazam
Tariqulazam

Reputation: 4585

Try using jQuery.parseJSON http://api.jquery.com/jQuery.parseJSON/

Upvotes: 0

Peter Olson
Peter Olson

Reputation: 142911

return object.concepts;

will return the concepts array.

If you just want retrieve the text of the first element, you could do something like this:

return object.concepts[0].text;

Upvotes: 1

Related Questions