如何查询JSON对象 [英] How to query a JSON object

查看:163
本文介绍了如何查询JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我AngularJS的web应用程序,我怎么可以查询JSON对象?

例如在下面的JSON对象我怎么能找到的值 reportTypeLabel ,其中 reportTypeId = 3

JSON:

  [
   {
      reportTypeId:5,
      REPORTTYPE code:FINREP
      reportTypeLabel:财务报告
   },
   {
      reportTypeId:9000002,
      REPORTTYPE code:REM HE
      reportTypeLabel:高收入者
   },
   {
      reportTypeId:3,
      REPORTTYPE code:COREP LE
      reportTypeLabel:大曝光 - COREP
   }
]


解决方案

如果你要大量使用数据操纵,我会强烈建议使用JS库,喜欢的强调 lodash

例如,使用下划线

  //假设你的对象被称为数据VAR的结果= _.findWhere(数据,{
    reportTypeId:3
})reportTypeLabel;
//结果===大曝光 - COREP

In my AngularJS web app, How can I query a JSON object ?

For example in the below JSON object how can I find the value of reportTypeLabel where reportTypeId=3

JSON:

[  
   {  
      reportTypeId:5,
      reportTypeCode:"FINREP",
      reportTypeLabel:"Financial Reporting"
   },
   {  
      reportTypeId:9000002,
      reportTypeCode:"REM HE",
      reportTypeLabel:"High Earners"
   },
   {  
      reportTypeId:3,
      reportTypeCode:"COREP LE",
      reportTypeLabel:"Large Exposures - COREP"
   }
]

解决方案

If you're going to use data manipulation extensively, I'd highly recommend using a JS library, like underscore or lodash.

For example, using underscore:

// assuming your object is called data

var result = _.findWhere(data, {
    reportTypeId: 3
}).reportTypeLabel;
// result === 'Large Exposures - COREP'

这篇关于如何查询JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆