0
복잡한 객체 (배열이있는 객체 포함) 존재 여부를 확인해야합니다. 이 주제에 대한 여러 게시물을 찾았습니다. 가장 많이 방문한 게시물은 아래에 있습니다. 제공된 솔루션 (checkNested 함수)의 문제점은 배열이있는 객체에서는 작동하지 않습니다. 누구에게도이 사건을 다루는 해결책이 있습니까?배열을 사용하여 객체에 객체 키 존재 여부에 대한 자바 스크립트 테스트
건배.
javascript test for existence of nested object key
이 내가 테스트 기능
는 :{
"_msgid": "3ae30deb.af9962",
"topic": "",
"payload": "I am really upset terrible service",
"error": null,
"parts": {
"id": "3ae30deb.af9962",
"type": "array",
"count": 2,
"len": 1,
"index": 0
},
"case_id": "0001",
"features": {
"usage": {
"text_units": 1,
"text_characters": 34,
"features": 7
},
"sentiment": {
"document": {
"score": -0.912124,
"label": "negative"
}
},
"semantic_roles": [{
"subject": {
"text": "I"
},
"sentence": "I am really upset terrible service",
"object": {
"text": "really upset terrible service",
"keywords": [{
"text": "terrible service"
}]
},
"action": {
"verb": {
"text": "be",
"tense": "present"
},
"text": "am",
"normalized": "be"
}
}],
"language": "en",
"keywords": [{
"text": "terrible service",
"sentiment": {
"score": -0.912124
},
"relevance": 0.902721,
"emotion": {
"sadness": 0.462285,
"joy": 0.002207,
"fear": 0.125395,
"disgust": 0.17766,
"anger": 0.575927
}
}],
"entities": [],
"emotion": {
"document": {
"emotion": {
"sadness": 0.462285,
"joy": 0.002207,
"fear": 0.125395,
"disgust": 0.17766,
"anger": 0.575927
}
}
},
"concepts": [],
"categories": [{
"score": 0.99946,
"label": "/health and fitness/disease/headaches and migraines"
}, {
"score": 0.0155692,
"label": "/education/school"
}, {
"score": 0.0141217,
"label": "/family and parenting/children"
}]
}
}
그리고 실패 테스트 :
console.log(checkProperty(msg, 'features.keywords[0].text') ? msg.features.keywords[0].text : "NA");
함께 작업 할 수있는 예제를 제공 할 수 있습니까? – Beau
배열과 파트를 추가 할 수 있습니다. –
지금까지 시도한 개체 및 코드 샘플을 게시하십시오. –