最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get specific element in JSON - Stack Overflow

programmeradmin4浏览0评论

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].id
Share 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
Add a ment  | 

4 Answers 4

Reset to default 11

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.

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));
}
发布评论

评论列表(0)

  1. 暂无评论