直接访问JSON对象属性并将其记录 [英] Accessing JSON object properties directly and log it
本文介绍了直接访问JSON对象属性并将其记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试直接访问JSON对象属性并将其记录下来,这是我的功能:
I'm trying to access JSON Object properties directly and log it, here is my function :
loadProcesses(filter?){
this._postService.getAllProcess(filter)
.subscribe(
res=> {
this.processListe = res;
// console.log(this.processListe.)
}
,null,
() =>{
console.log("get processes liste" + filter)
});
因此this.processListe包含一个JSON对象,而我的JSON格式如下:
So this.processListe contain a JSON Object, and my JSON format is like this:
{"Person": {
"id": "A256",
"name": "GET",
"status": "active",
"description": "hardworking, openminded",
...
因此它将包含完全相同的内容,例如,如果我只想在控制台日志上打印标签,我该怎么做?
So it will contains exactly the same things, for example if i want to simply print the label on a console log how can i do it ??
推荐答案
您是否正在寻找类似的东西:
Are you looking for something like this:
function parseObject(obj)
{
for(var key in obj)
{
console.log("key: " + key + ", value: " + obj[key])
if(obj[key] instanceof Object)
{
parseObject(obj[key]);
}
}
}
只需在subscribe方法中调用parseObject(res).
just call parseObject(res) in the subscribe method.
这篇关于直接访问JSON对象属性并将其记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文