过滤从 API 中提取的数据以仅读取特定值
Filter data pulled from API to only read specific values
我正在通过 API 提取所有客户信息并将其打印在控制台中。
我用
做这个
if (this.readyState === 4) {
console.log('Body:', this.responseText);
}
};
它给出了以下所有数据(由于显而易见的原因而更改)
{"id":2,"userIdent":"11","randomInfo":null,"isLead":false,"clientType":1,"companyName":null,"companyRegistrationNumber":null,"companyTaxId":null,"companyWebsite":null,"street1":"1234 Happy Rd","street2":null,"city":"Smile City","countryId":249,"stateId":22,"zipCode":"12345","fullAddress":"1234 Happy Rd, Smile City, MI","invoiceStreet1":null,"invoiceStreet2":null,"invoiceCity":null,"invoiceStateId":null,"invoiceCountryId":null,"invoiceZipCode":null,"invoiceAddressSameAsContact":true,"note":null,"sendInvoiceByPost":null,"invoiceMaturityDays":null,"stopServiceDue":null,"stopServiceDueDays":null,"organizationId":2,"tax1Id":null,"tax2Id":null,"tax3Id":null,"registrationDate":"2022-03-07T00:00:00-0500","leadConvertedAt":null,"companyContactFirstName":null,"companyContactLastName":null,"isActive":false,"firstName":"boop":[],"accountBalance":0.0,"accountCredit":0.0,"accountOutstanding":0.0,"currencyCode":"USD","organizationName":"My Company","bankAccounts":[],"tags":[],"invitationEmailSentDate":null,"avatarColor":"#ef6c00","addressGpsLat":11.22,"addressGpsLon":-22.11,"isArchived":false,"generateProformaInvoices":null,"usesProforma":false,"hasOverdueInvoice":false,"hasOutage":true,"hasSuspendedService":false,"hasServiceWithoutDevices":false,"referral":null}
我只想提取与“userIdent”相关的值,例如 11,但是当我从 api 中提取数据时,我不确定如何执行此操作.
你需要添加这个
var data = JSON.parse(this.responseText);
var userIdent = data['userIdent'];
console.log(userIdent);
const { userIdent } = JSON.parse(this.responseText)
console.log(userIdent) // "11"
我正在通过 API 提取所有客户信息并将其打印在控制台中。
我用
做这个 if (this.readyState === 4) {
console.log('Body:', this.responseText);
}
};
它给出了以下所有数据(由于显而易见的原因而更改)
{"id":2,"userIdent":"11","randomInfo":null,"isLead":false,"clientType":1,"companyName":null,"companyRegistrationNumber":null,"companyTaxId":null,"companyWebsite":null,"street1":"1234 Happy Rd","street2":null,"city":"Smile City","countryId":249,"stateId":22,"zipCode":"12345","fullAddress":"1234 Happy Rd, Smile City, MI","invoiceStreet1":null,"invoiceStreet2":null,"invoiceCity":null,"invoiceStateId":null,"invoiceCountryId":null,"invoiceZipCode":null,"invoiceAddressSameAsContact":true,"note":null,"sendInvoiceByPost":null,"invoiceMaturityDays":null,"stopServiceDue":null,"stopServiceDueDays":null,"organizationId":2,"tax1Id":null,"tax2Id":null,"tax3Id":null,"registrationDate":"2022-03-07T00:00:00-0500","leadConvertedAt":null,"companyContactFirstName":null,"companyContactLastName":null,"isActive":false,"firstName":"boop":[],"accountBalance":0.0,"accountCredit":0.0,"accountOutstanding":0.0,"currencyCode":"USD","organizationName":"My Company","bankAccounts":[],"tags":[],"invitationEmailSentDate":null,"avatarColor":"#ef6c00","addressGpsLat":11.22,"addressGpsLon":-22.11,"isArchived":false,"generateProformaInvoices":null,"usesProforma":false,"hasOverdueInvoice":false,"hasOutage":true,"hasSuspendedService":false,"hasServiceWithoutDevices":false,"referral":null}
我只想提取与“userIdent”相关的值,例如 11,但是当我从 api 中提取数据时,我不确定如何执行此操作.
你需要添加这个
var data = JSON.parse(this.responseText);
var userIdent = data['userIdent'];
console.log(userIdent);
const { userIdent } = JSON.parse(this.responseText)
console.log(userIdent) // "11"