繁体   English   中英

如何从 JSON fromat 中提取特定字段和值

[英]How to extract specific fields and values from a JSON fromat

我有一个来自响应正文的 JSON output 如下

我只想拉

  1. “合同ID”和
  2. “合同状态”。

我正在使用 javascript 从响应正文中提取数据

 { "value": [ { "title": "Test Ariba IT contract", "description": "", "commodities": [ { "uniqueName": "3.99", "domain": "custom", "name": "OTHER ENGINEERING SERVICES" } ], "regions": [ { "uniqueName": "700", "name": "US Procurement" } ], "departments": [ ], "owner": { "uniqueName": "Gautam.KumarBans", "passwordAdapter": "PasswordAdapter1", "name": "Gautam Bansal", "emailAddress": "Gautam.KumarBansa", "organization": "NaTEST", "orgANId": "AN01002048300-T", "orgName": "NatioST", "timeZoneID": "America/New_York", "localeID": "[ariba.basic.core.LocaleID [BaseId 1497 AAAAAB7XZ 15l.3f]]" }, "contractId": "CW1948133", "contractStatus": "Draft", "supplier": { "name": "[CM] KIER GROUP", "systemID": "50066293", "smVendorID": null, "organizationIDs": [ { "domain": "buyersystemid", "value": "50066293" } ], "address": { "name": "50066293", "uniqueName": "50066293", "phone": "", "fax": "", "city": "", "state": "", "postalCode": "" } }, "effectiveDate": "2020-12-21T00:00:00.000+0000", "agreementDate": "2020-12-21T00:00:00.000+0000", "expirationDate": "2021-12-21T00:00:00.000+0000", "creationDate": "2020-12-21T21:11:10.486+0000", "contractAmount": { "amount": 1000.0000000000, "currency": "USD" }, "version": 1, "templateId": "CW1945605", "amendmentType": "", "amendmentReason": "", "origin": 0, "hierarchicalType": "StandAlone", "expirationTermType": "Fixed", "accessControl": [ "Private To Team Members" ], "relatedId": "NA", "affectedParties": [ { "name": "[CM] KIER GROUP", "systemID": "50066293", "smVendorID": null, "organizationIDs": [ { "domain": "buyersystemid", "value": "50066293" } ], "address": { "name": "50066293", "uniqueName": "50066293", "phone": "", "fax": "", "city": "", "state": "", "postalCode": "" } } ], "maximumNumberOfRenewals": 0, "autoRenewalInterval": 0, "isTestProject": true, "customFields": [ { "fieldId": "cus_ThirdPartyUpliftsDetails", "fieldName": "Third Party Uplifts Details", "fieldDataType": "multiLineTextValue", "booleanValue": null, "dateValue": null, "bigDecimalValue": null, "intValue": null, "moneyValue": null, "textValue": null, "multiLineTextValue": [ ], "textMultiSelectValue": null, "percentValue": null, "urlValue": null, "userMultiSelectValue": null, "uomValue": null, "regionValue": null, "productValue": null, "addressValue": null, "commodityValue": null, "countryValue": null, "currencyValue": null, "departmentValue": null, "flexMasterDataFieldClassName": null, "flexMasterDataTypeValue": null, "uniqueName": null, "subContent": null, "templateProperties": [ "TextArea1000Field", "FullAmendmentEditField", "ForceRefreshField", "ZoneRightField" ], "enumerationValues": null, "visibilityConstraint": null, "editabilityConstraint": null, "validityConstraint": null, "instanceOfSubContent": { "flexMasterDataFields": null }, "customField": true }, { "fieldId": "cus_PreviousBuyer", "fieldName": "Previous Buyer", "fieldDataType": "textValue", "booleanValue": null, "dateValue": null, "bigDecimalValue": null, "intValue": null, "moneyValue": null, "textValue": [ null ], "multiLineTextValue": null, "textMultiSelectValue": null, "percentValue": null, "urlValue": null, "userMultiSelectValue": null, "uomValue": null, "regionValue": null, "productValue": null, "addressValue": null, "commodityValue": null, "countryValue": null, "currencyValue": null, "departmentValue": null, "flexMasterDataFieldClassName": null, "flexMasterDataTypeValue": null, "uniqueName": null, "subContent": null, "templateProperties": [ "String1000Field" ], "enumerationValues": null, "visibilityConstraint": null, "editabilityConstraint": null, "validityConstraint": null, "instanceOfSubContent": { "flexMasterDataFields": null }, "customField": true }, { "fieldId": "cus_GroupTier", "fieldName": "Group Tier", "fieldDataType": "textValue", "booleanValue": null, "dateValue": null, "bigDecimalValue": null, "intValue": null, "moneyValue": null, "textValue": [ null ], "multiLineTextValue": null, "textMultiSelectValue": null, "percentValue": null, "urlValue": null, "userMultiSelectValue": null, "uomValue": null, "regionValue": null, "productValue": null, "addressValue": null, "commodityValue": null, "countryValue": null, "currencyValue": null, "departmentValue": null, "flexMasterDataFieldClassName": null, "flexMasterDataTypeValue": null, "uniqueName": null, "subContent": null, "templateProperties": [ "String1000Field", "PickListField", "FullAmendmentEditField", "AdministrativeEditField", "TerminationEditField" ], "enumerationValues": null, "visibilityConstraint": null, "editabilityConstraint": null, "validityConstraint": null, "instanceOfSubContent": { "flexMasterDataFields": null }, "customField": true }, { "fieldId": "cus_SuboptimalTCs", "fieldName": "Suboptimal T&Cs", "fieldDataType": "booleanValue", "booleanValue": null, "dateValue": null, "bigDecimalValue": null, "intValue": null, "moneyValue": null, "textValue": null, "multiLineTextValue": null, "textMultiSelectValue": null, "percentValue": null, "urlValue": null, "userMultiSelectValue": null, "uomValue": null, "regionValue": null, "productValue": null, "addressValue": null, "commodityValue": null, "countryValue": null, "currencyValue": null, "departmentValue": null, "flexMasterDataFieldClassName": null, "flexMasterDataTypeValue": null, "uniqueName": null, "subContent": null, "templateProperties": [ "BooleanField", "FullAmendmentEditField", "ZoneRightField" ], "enumerationValues": null, "visibilityConstraint": null, "editabilityConstraint": null, "validityConstraint": null, "instanceOfSubContent": { "flexMasterDataFields": null }, "customField": true } ] } ], "count": null, "start": null, "warnings": null }

我有一个来自响应正文的 JSON output 如下

我只想拉

  1. “合同ID”和
  2. “合同状态”。

我正在使用 javascript 从响应正文中提取数据

 const response = { "value": [{ "title": "Test Ariba IT contract", "description": "", "commodities": [{ "uniqueName": "3.99", "domain": "custom", "name": "OTHER ENGINEERING SERVICES" }], "regions": [{ "uniqueName": "700", "name": "US Procurement" }], "departments": [], "owner": { "uniqueName": "Gautam.KumarBans", "passwordAdapter": "PasswordAdapter1", "name": "Gautam Bansal", "emailAddress": "Gautam.KumarBansa", "organization": "NaTEST", "orgANId": "AN01002048300-T", "orgName": "NatioST", "timeZoneID": "America/New_York", "localeID": "[ariba.basic.core.LocaleID [BaseId 1497 AAAAAB7XZ 15l.3f]]" }, "contractId": "CW1948133", "contractStatus": "Draft", "supplier": { "name": "[CM] KIER GROUP", "systemID": "50066293", "smVendorID": null, "organizationIDs": [{ "domain": "buyersystemid", "value": "50066293" }], "address": { "name": "50066293", "uniqueName": "50066293", "phone": "", "fax": "", "city": "", "state": "", "postalCode": "" } }, "effectiveDate": "2020-12-21T00:00:00.000+0000", "agreementDate": "2020-12-21T00:00:00.000+0000", "expirationDate": "2021-12-21T00:00:00.000+0000", "creationDate": "2020-12-21T21:11:10.486+0000", "contractAmount": { "amount": 1000.0000000000, "currency": "USD" }, "version": 1, "templateId": "CW1945605", "amendmentType": "", "amendmentReason": "", "origin": 0, "hierarchicalType": "StandAlone", "expirationTermType": "Fixed", "accessControl": ["Private To Team Members"], "relatedId": "NA", "affectedParties": [{ "name": "[CM] KIER GROUP", "systemID": "50066293", "smVendorID": null, "organizationIDs": [{ "domain": "buyersystemid", "value": "50066293" }], "address": { "name": "50066293", "uniqueName": "50066293", "phone": "", "fax": "", "city": "", "state": "", "postalCode": "" } }], "maximumNumberOfRenewals": 0, "autoRenewalInterval": 0, "isTestProject": true, "customFields": [{ "fieldId": "cus_ThirdPartyUpliftsDetails", "fieldName": "Third Party Uplifts Details", "fieldDataType": "multiLineTextValue", "booleanValue": null, "dateValue": null, "bigDecimalValue": null, "intValue": null, "moneyValue": null, "textValue": null, "multiLineTextValue": [], "textMultiSelectValue": null, "percentValue": null, "urlValue": null, "userMultiSelectValue": null, "uomValue": null, "regionValue": null, "productValue": null, "addressValue": null, "commodityValue": null, "countryValue": null, "currencyValue": null, "departmentValue": null, "flexMasterDataFieldClassName": null, "flexMasterDataTypeValue": null, "uniqueName": null, "subContent": null, "templateProperties": ["TextArea1000Field", "FullAmendmentEditField", "ForceRefreshField", "ZoneRightField"], "enumerationValues": null, "visibilityConstraint": null, "editabilityConstraint": null, "validityConstraint": null, "instanceOfSubContent": { "flexMasterDataFields": null }, "customField": true }, { "fieldId": "cus_PreviousBuyer", "fieldName": "Previous Buyer", "fieldDataType": "textValue", "booleanValue": null, "dateValue": null, "bigDecimalValue": null, "intValue": null, "moneyValue": null, "textValue": [null], "multiLineTextValue": null, "textMultiSelectValue": null, "percentValue": null, "urlValue": null, "userMultiSelectValue": null, "uomValue": null, "regionValue": null, "productValue": null, "addressValue": null, "commodityValue": null, "countryValue": null, "currencyValue": null, "departmentValue": null, "flexMasterDataFieldClassName": null, "flexMasterDataTypeValue": null, "uniqueName": null, "subContent": null, "templateProperties": ["String1000Field"], "enumerationValues": null, "visibilityConstraint": null, "editabilityConstraint": null, "validityConstraint": null, "instanceOfSubContent": { "flexMasterDataFields": null }, "customField": true }, { "fieldId": "cus_GroupTier", "fieldName": "Group Tier", "fieldDataType": "textValue", "booleanValue": null, "dateValue": null, "bigDecimalValue": null, "intValue": null, "moneyValue": null, "textValue": [null], "multiLineTextValue": null, "textMultiSelectValue": null, "percentValue": null, "urlValue": null, "userMultiSelectValue": null, "uomValue": null, "regionValue": null, "productValue": null, "addressValue": null, "commodityValue": null, "countryValue": null, "currencyValue": null, "departmentValue": null, "flexMasterDataFieldClassName": null, "flexMasterDataTypeValue": null, "uniqueName": null, "subContent": null, "templateProperties": ["String1000Field", "PickListField", "FullAmendmentEditField", "AdministrativeEditField", "TerminationEditField"], "enumerationValues": null, "visibilityConstraint": null, "editabilityConstraint": null, "validityConstraint": null, "instanceOfSubContent": { "flexMasterDataFields": null }, "customField": true }, { "fieldId": "cus_SuboptimalTCs", "fieldName": "Suboptimal T&Cs", "fieldDataType": "booleanValue", "booleanValue": null, "dateValue": null, "bigDecimalValue": null, "intValue": null, "moneyValue": null, "textValue": null, "multiLineTextValue": null, "textMultiSelectValue": null, "percentValue": null, "urlValue": null, "userMultiSelectValue": null, "uomValue": null, "regionValue": null, "productValue": null, "addressValue": null, "commodityValue": null, "countryValue": null, "currencyValue": null, "departmentValue": null, "flexMasterDataFieldClassName": null, "flexMasterDataTypeValue": null, "uniqueName": null, "subContent": null, "templateProperties": ["BooleanField", "FullAmendmentEditField", "ZoneRightField"], "enumerationValues": null, "visibilityConstraint": null, "editabilityConstraint": null, "validityConstraint": null, "instanceOfSubContent": { "flexMasterDataFields": null }, "customField": true }] }], "count": null, "start": null, "warnings": null } const new_object = response.value.map(({ contractId, contractStatus }) => { return { contractId, contractStatus }; }); console.log(new_object);

你应该首先了解 json,看这里: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM