Так как я работаю с SOAP API, который возвращает XML, и мне нужен / нужен JSON после ответа xml2json, это именно то, что я получаю: Ticket! Мне, например, нужно: описание билета, заголовок билета, номер билета ... еще несколько, но для демонстрационных целей достаточно 3
Быть объектом JSON ниже настолько неприятно ... что лучше или лучшеэффективный способ получить то, что мне нужно выше: -описание тикета -титл названия тикета-номер тикета
В JSON вы можете найти объекты с именами: Описание, Название, Номер тикета (все строки)
Я думал о том, чтобы сделать его массивом или массивом, используя Object.entries (JSON)
, а затем выяснить, насколько глубоко этот массив массивов использует рекурсивную функцию.
Может быть, затем попытатьсявыровнять массивы массивов на любую глубину, найденную выше.
Но я все еще продолжаю смешивать массивы и объекты.
ПОМОГИТЕ!
const flattened = [
"declaration",
{ attributes: { version: "1.0", encoding: "utf-8" } },
"elements",
{
type: "element",
name: "soap:Envelope",
attributes: {
"xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:xsd": "http://www.w3.org/2001/XMLSchema"
},
elements: [
{
type: "element",
name: "soap:Body",
elements: [
{
type: "element",
name: "queryResponse",
attributes: { xmlns: "http://autotask.net/ATWS/v1_6/" },
elements: [
{
type: "element",
name: "queryResult",
elements: [
{
type: "element",
name: "ReturnCode",
elements: [{ type: "text", text: "1" }]
},
{
type: "element",
name: "EntityResults",
elements: [
{
type: "element",
name: "Entity",
attributes: { "xsi:type": "Ticket" },
elements: [
{
type: "element",
name: "id",
elements: [{ type: "text", text: "40218" }]
},
{
type: "element",
name: "UserDefinedFields",
elements: [
{
type: "element",
name: "UserDefinedField",
elements: [
{
type: "element",
name: "Name",
elements: [
{ type: "text", text: "Kaseya Alert ID" }
]
}
]
},
{
type: "element",
name: "UserDefinedField",
elements: [
{
type: "element",
name: "Name",
elements: [
{ type: "text", text: "Kaseya Ticket ID" }
]
}
]
},
{
type: "element",
name: "UserDefinedField",
elements: [
{
type: "element",
name: "Name",
elements: [
{ type: "text", text: "Logicalis ticket" }
]
},
{
type: "element",
name: "Value",
elements: [{ type: "text", text: "yes" }]
}
]
}
]
},
{
type: "element",
name: "AccountID",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "0" }]
},
{
type: "element",
name: "AllocationCodeID",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "29682804" }]
},
{
type: "element",
name: "CreateDate",
attributes: { "xsi:type": "xsd:dateTime" },
elements: [
{ type: "text", text: "2019-09-24T13:56:45.47" }
]
},
{
type: "element",
name: "CreatorResourceID",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "29682933" }]
},
{
type: "element",
name: "Description",
attributes: { "xsi:type": "xsd:string" },
elements: [
{
type: "text",
text:
"my description"
}
]
},
{
type: "element",
name: "DueDateTime",
attributes: { "xsi:type": "xsd:dateTime" },
elements: [
{ type: "text", text: "2019-09-24T14:56:45.47" }
]
},
{
type: "element",
name: "EstimatedHours",
attributes: { "xsi:type": "xsd:decimal" },
elements: [{ type: "text", text: "0.0000" }]
},
{
type: "element",
name: "IssueType",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "12" }]
},
{
type: "element",
name: "LastActivityDate",
attributes: { "xsi:type": "xsd:dateTime" },
elements: [
{ type: "text", text: "2019-10-14T11:12:59.337" }
]
},
{
type: "element",
name: "Priority",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "1" }]
},
{
type: "element",
name: "QueueID",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "29682969" }]
},
{
type: "element",
name: "AssignedResourceID",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "29682919" }]
},
{
type: "element",
name: "AssignedResourceRoleID",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "29683464" }]
},
{
type: "element",
name: "Source",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "4" }]
},
{
type: "element",
name: "Status",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "1" }]
},
{
type: "element",
name: "SubIssueType",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "146" }]
},
{
type: "element",
name: "TicketNumber",
attributes: { "xsi:type": "xsd:string" },
elements: [{ type: "text", text: "T20190924.0157" }]
},
{
type: "element",
name: "Title",
attributes: { "xsi:type": "xsd:string" },
elements: [
{
type: "text",
text:
"enabling file share/external sharing in Microsoft Teams"
}
]
},
{
type: "element",
name: "FirstResponseDueDateTime",
attributes: { "xsi:type": "xsd:dateTime" },
elements: [
{ type: "text", text: "2019-09-24T14:26:45.47" }
]
},
{
type: "element",
name: "ResolvedDueDateTime",
attributes: { "xsi:type": "xsd:dateTime" },
elements: [
{ type: "text", text: "2019-09-24T14:56:45.47" }
]
},
{
type: "element",
name: "ServiceLevelAgreementID",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "2" }]
},
{
type: "element",
name: "Resolution",
attributes: { "xsi:type": "xsd:string" }
},
{
type: "element",
name: "PurchaseOrderNumber",
attributes: { "xsi:type": "xsd:string" }
},
{
type: "element",
name: "TicketType",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "1" }]
},
{
type: "element",
name: "ChangeInfoField1",
attributes: { "xsi:type": "xsd:string" }
},
{
type: "element",
name: "ChangeInfoField2",
attributes: { "xsi:type": "xsd:string" }
},
{
type: "element",
name: "ChangeInfoField3",
attributes: { "xsi:type": "xsd:string" }
},
{
type: "element",
name: "ChangeInfoField4",
attributes: { "xsi:type": "xsd:string" }
},
{
type: "element",
name: "ChangeInfoField5",
attributes: { "xsi:type": "xsd:string" }
},
{
type: "element",
name: "LastCustomerVisibleActivityDateTime",
attributes: { "xsi:type": "xsd:dateTime" },
elements: [
{ type: "text", text: "2019-10-14T11:12:59.273" }
]
},
{
type: "element",
name: "HoursToBeScheduled",
attributes: { "xsi:type": "xsd:decimal" },
elements: [{ type: "text", text: "0.0000" }]
},
{
type: "element",
name: "TicketCategory",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "3" }]
},
{
type: "element",
name: "ExternalID",
attributes: { "xsi:type": "xsd:string" }
},
{
type: "element",
name: "CreatorType",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "1" }]
},
{
type: "element",
name: "AccountPhysicalLocationID",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "1" }]
},
{
type: "element",
name: "LastActivityPersonType",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "1" }]
},
{
type: "element",
name: "LastActivityResourceID",
attributes: { "xsi:type": "xsd:int" },
elements: [{ type: "text", text: "29682919" }]
}
]
}
]
},
{
type: "element",
name: "EntityResultType",
elements: [{ type: "text", text: "ticket" }]
},
{ type: "element", name: "Errors" },
{
type: "element",
name: "EntityReturnInfoResults",
elements: [
{
type: "element",
name: "EntityReturnInfo",
elements: [
{
type: "element",
name: "EntityId",
elements: [{ type: "text", text: "40218" }]
},
{
type: "element",
name: "DatabaseAction",
elements: [{ type: "text", text: "None" }]
},
{
type: "element",
name: "DuplicateStatus",
elements: [
{
type: "element",
name: "Found",
elements: [{ type: "text", text: "false" }]
},
{ type: "element", name: "MatchInfo" },
{
type: "element",
name: "Ignored",
elements: [{ type: "text", text: "false" }]
}
]
},
{ type: "element", name: "Message" }
]
}
]
}
]
}
]
}
]
}
]
}
];