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
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].idShare Improve this question asked Apr 15, 2011 at 23:06 rabid_zombierabid_zombie 9922 gold badges16 silver badges32 bronze badges 2
- A JavaScript object literal is not JSON – Quentin Commented Apr 15, 2011 at 23:08
- To be more specific, the JSON is a response from a POST that I do. I save it to a variable response and I want to get that specific element. – rabid_zombie Commented Apr 15, 2011 at 23:10
4 Answers
Reset to default 11Simple:
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.
Just response.id
. You don't need anything more.
You should just need to use:
response.id
dynamic func_param = JsonConvert.DeserializeObject(key);
foreach (var invoicekey in func_param)
{
var invoice = merchelloHelper.Query.Invoice.GetByKey(Guid.Parse(invoicekey.Value));
}