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
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.
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.
It has no special meaning to JSON. This particular data uses it as a key string.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With