有一个如下对象:
要求输入属性和这个属性的深度,输出这个属性对应的值
为什么不能直接输入 属性,因为可能会重名,上面JSON中最外层的Status
和Result下的Status
就是同名
findValue(key,depth)
{
"Status":"200",
"Message":"查询成功",
"OrderNumber":null,
"Result":{
"Partners":[
{
"StockName":"xx",
"StockType":"自然人股东",
"StockPercent":"49.1900%",
"ShouldCapi":"491.900000"
}
],
"Employees":[
{
"Name":"xx",
"Job":"执行董事"
},
{
"Name":"xx",
"Job":"经理"
}
],
"Branches":[
{
"CompanyId":"8dc057af59e908b6a1c05d74de114134",
"RegNo":"500902300083458",
"Name":"北京小桔科技有限公司重庆分公司",
"BelongOrg":"重庆市工商行政管理局南岸区分局经开区局",
"CreditCode":null,
"OperName":"xx"
}
],
"ChangeRecords":[
{
"ProjectName":"投资人",
"BeforeContent":"自然人股东;",
"AfterContent":"人股东;",
"ChangeDate":"2017-07-21T00:00:00+08:00"
}
],
"ContactInfo":{
"WebSite":[
{
"Name":null,
"Url":"www.xiaojukeji.com"
}
],
"PhoneNumber":"010-83043726",
"Email":"zhangyimei@diditaxi.com.cn"
},
"Industry":{
"Industry":"科学研究和技术服务业",
"SubIndustry":"科技推广和应用服务业"
},
"KeyNo":"4659626b1e5e43f1bcad8c268753216e",
"Name":"北京小桔科技有限公司",
"No":"110108015068911",
"BelongOrg":"海淀分局",
"OperName":"程维",
"StartDate":"2012-07-10T00:00:00+08:00",
"EndDate":null,
"Status":""
}
}
比如
findval("Partners",2)输出
[{
"StockName":"xx",
"StockType":"自然人股东",
"StockPercent":"49.1900%",
"ShouldCapi":"491.900000"
}
]
findVal("WebSite",3)输出
[{
"Name":null,
"Url":"www.xiaojukeji.com"
}],
findVal("WebSite",3)输出
下面函数用法
findVal("WebSite", 3, obj)
其中的obj为你查找的对象,返回的是一个数组,包含满足条件的所有值。