Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get specific element in JSON

If I have JSON that is:

var response = {results: 2938; id: 9283};

How can I get id using javascript/jquery?

I tried something like but I can't seem to get what I want (I want to get the number in id):

response[1]

and

response[1].id
like image 907
rabid_zombie Avatar asked Apr 15 '11 23:04

rabid_zombie


People also ask

How can I get specific data from JSON?

Getting a specific property from a JSON response object Instead, you select the exact property you want and pull that out through dot notation. The dot ( . ) after response (the name of the JSON payload, as defined arbitrarily in the jQuery AJAX function) is how you access the values you want from the JSON object.

Can we search in JSON file?

The Custom Search JSON API lets you develop websites and applications to retrieve and display search results from Programmable Search Engine programmatically. With this API, you can use RESTful requests to get either web search or image search results in JSON format.

What does '@' mean in JSON?

It has no special meaning to JSON. This particular data uses it as a key string.


1 Answers

Simple:

response.id

With that being said, your json is invalid,

var response = {results: 2938; id: 9283};

Use a , to separate items not a ;

var response = {results: 2938, id: 9283};

And since I love jsfiddle so much, here is an example.

like image 162
Mark Coleman Avatar answered Oct 11 '22 12:10

Mark Coleman