[英]Need to access the array of Child object from the Parent object in Javascript
PostResponseOutput(TextedValue):Promise<any>
{
var options = {
method: 'POST',
url: 'http://NHSSQLCHNE8105:8081/ctakes-web-rest/service/analyzejson?
pipeline=default',
headers: {
'Accept': 'application/json',
'Content-Type' : 'application/json'
},
body: TextedValue
};
await request(options, callback);
async function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var info = await JSON.parse(body);
}
}}
使用npm請求,我得到json的主體,並使用JSON.parse(body)將下面的JSON文件轉換為對象列表。 我需要訪問子對象中的數組。 但是由於子對象是根據我們提供的輸入動態更改的,因此無法在代碼中獲取子對象的數組。 任何人都可以在不訪問Child對象的情況下幫助從父對象獲取數組。
我需要刪除動態更改的子對象,並需要從父對象訪問其數組。 注意:PARENT OBject不會根據input進行更改。 根據輸入是否具有值
{
// This is the Allergy Object. which doesn't have any Value for the input
Admit
"Allergy": {},
// This is the Others Object. which has 1 Value for the input Admit
"Others": {
**"Health Care Activity~T058~Hospital admission":** [
"codingScheme: SNOMEDCT_US",
"code: 32485007",
"cui: C0184666",
"semanticType: Health Care Activity",
"tui: T058",
"preferredtext: Hospital admission"
]
},
// This is the AnatomicalSiteMention Object. which doesn't have any Value
for the input Admit
"AnatomicalSiteMention": {},
// This is the MedicationMention Object. which doesn't have any Value for the
input Admit
"MedicationMention": {},
// This is the DrugChangeStatusAnnotation Object. which doesn't have any
Value for the input Admit
"DrugChangeStatusAnnotation": {},
// This is the DrugChangeStatusAnnotation Object. which doesn't have any
Value for the input Admit
"StrengthAnnotation": {},
// This is the Request Object. which doesn't have any Value for the input
Admit
"Request": {},
// This is the FractionStrengthAnnotation Object. which doesn't have any
Value for the input Admit
"FractionStrengthAnnotation": {},
// This is the FrequencyUnitAnnotation Object. which doesn't have any Value
for the input Admit
"FrequencyUnitAnnotation": {},
// This is the DiseaseDisorderMention Object. which doesn't have any Value
for the input Admit
"DiseaseDisorderMention": {},
// This is the FamilyMember Object. which doesn't have any Value for the
input Admit
"FamilyMember": {},
// This is the SignSymptomMention Object. which doesn't have any Value for
the input Admit
"SignSymptomMention": {},
// This is the RouteAnnotation Object. which doesn't have any Value for the
input Admit
"RouteAnnotation": {},
// This is the DateAnnotation Object which doesn't have any Value for the
input Admit
"DateAnnotation": {},
// This is the MeasurementAnnotation Object. which doesn't have any Value for
the input Admit
"MeasurementAnnotation": {},
// This is the RelationDetails Object. which doesn't have 1 Child object
Value for the input Admit
"RelationDetails": {
**"RELATIONS:":** [
"\n"
]
},
// This is the TimeMention. which doesn't have 1 Child object Value for the
input Admit
"TimeMention": {},
// This is the ProcedureMention. which doesn't have 1 Child object Value for
the input Admit
"ProcedureMention": {},
// This is the StrengthUnitAnnotation object. which doesn't have 1 Child
object Value for the input Admit
"StrengthUnitAnnotation": {},
// This is the Health Care activity Object. which doesn't have 1 Child object
Value for the input Admit
"Health Care activity": {
**"Hospital admission":** [
"start:1",
"end:3",
"polarity:1",
"[codingScheme: SNOMEDCT_US, code: 32485007, cui: C0184666,
semanticType: Health Care Activity, tui: T058, preferredtext: Hospital
admission]"
]
},
// This is the AnalysisText object which doesn't have 1 Child object Value
for the input Admit
"AnalysisText": {
**"AnalysisText":** [
"admit\n ",
"admit\n "
]
}
}
我已加粗**子對象,這些對象將根據輸入而動態更改。 目前,我已經將Admit作為Postmantool中的輸入
您可以使用Object.values
檢索所有子對象值,而無需知道鍵。 這將是所有子項的所有值的數組。 因此,對於您的對象,您可以使用以下命令訪問數組:
let Admit = { "Allergy": {}, "Others": { "Health Care Activity~T058~Hospital admission": [ "codingScheme: SNOMEDCT_US", "code: 32485007", "cui: C0184666", "semanticType: Health Care Activity", "tui: T058", "preferredtext: Hospital admission" ] }, "AnatomicalSiteMention": {} // etc... } let othersObj = Admit.Others // children will have all the values of `others` children // you don't need to know 'Health Care Activity~T058~Hospital admission' let children = Object.values(othersObj) console.log(children[0])
您只需要小心一點,就知道可能有多少個孩子。 的about假設只有一個,因此我們可以使用children[0]
訪問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.