이것은 내 JSON입니다. 이제 속성이 배열 또는 문자열인지 확인하고 싶습니다.
{ "데이터": [
{
"name": "my Service",
"description":" comes once here " ,
"tables":{ "tables":["rajaaaaa ","rajuuuuu","mommmm"]},
"imgUrl":"../assets/images/nmpm.jpg"
},
{
"name": "my Service1",
"description":" comes once here " ,
"tables":{ "tables":["rajaaaaa ","rajuuuuu","mommmm"]},
"imgUrl":"../assets/images/nmpm.jpg"
},
{
"name": "my Service2",
"description":" comes once here " ,
"tables":{ "tables":["rajaaaaa ","rajuuuuu","mommmm"]},
"imgUrl":"../assets/images/nmpm.jpg"
},
{
"name": "my Service3",
"description":" comes once here " ,
"tables":{ "tables":["rajaaaaa ","rajuuuuu","mommmm"]},
"imgUrl":"../assets/images/nmpm.jpg"
}
]}
이제 속성을 찾는 방법은 문자열 또는 배열입니다.
각 속성 유형을 식별해야하므로 귀하의 답변을 이해했습니다. 아래 코드와 같이했습니다. 내가 당신의 길에 있지 않다면 알려주세요. 나는 모든 유형을 위로했다
var data = [
{
"name": "my Service",
"description":" comes once here " ,
"tables":{ "tables":["rajaaaaa ","rajuuuuu","mommmm"]},
"imgUrl":"../assets/images/nmpm.jpg"
},
{
"name": "my Service1",
"description":" comes once here " ,
"tables":{ "tables":["rajaaaaa ","rajuuuuu","mommmm"]},
"imgUrl":"../assets/images/nmpm.jpg"
},
{
"name": "my Service2",
"description":" comes once here " ,
"tables":{ "tables":["rajaaaaa ","rajuuuuu","mommmm"]},
"imgUrl":"../assets/images/nmpm.jpg"
},
{
"name": "my Service3",
"description":" comes once here " ,
"tables":{ "tables":["rajaaaaa ","rajuuuuu","mommmm"]},
"imgUrl":"../assets/images/nmpm.jpg"
}
];
data.forEach(obj=>{
var keys = Object.keys(obj);
for(var k=0;k< keys.length; k++){
if(typeof obj[keys[k]] == 'string'){
console.log(keys[k]+" is string");
}else if(typeof obj[keys[k]] == 'object'){
var obj_keys = Object.keys(obj[keys[k]]);
for(var j = 0; j< obj_keys.length; j++){
if(Object.prototype.toString.call( obj[keys[k]][obj_keys[j]] ) === '[object Array]') {
console.log(keys[k]+" has Array");
}
}
}
}
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다