我目前正在尝试按项目对json对象进行排序,我有一个报表对象,它持有一个应用程序和一个项目,我希望得到按项目分组的对象。这是我报告对象的json结构。这个结构将在json响应中重复:我将收到许多报告对象 有没有图书馆可以做到这一点?
{
"internalId": 60,
"state": "DIAGNOSIS_APPROVAL",
"project": {
"internalId": 25,
"acronym": "IMUPT",
"label": "IMUP216",
"comment": "",
"sap": "58",
"startingDate": 1488841200000,
"endingDate": 1553209200000,
"currency": {
"internalId": 143,
"currencyCode": "TND",
"currencyName": "Tunisian Dinar"
},
"budget": 250000000,
"defaultFrReportModelSet": {
"reference": "Sdr9r_fr.pdf",
"comment": "",
"active": false,
"expertPath": "",
"validatorPath": "",
"tuPath": "",
"bmnPath": "",
"locale": {
"internalId": 2,
"language": {
"internalId": 48,
"languageCode": "fr",
"languageName": "French"
}
},
"sections": []
},
"defaultEnReportModelSet": {
"reference": "Sdr9r.pdf",
"comment": "",
"active": false,
"expertPath": "C:\\pmn\\files\\200bba69-1be5-4640-b9e7-47f0d919145f\\srd9rTest.pdf",
"validatorPath": "",
"tuPath": "",
"bmnPath": "",
"locale": {
"internalId": 1,
"language": {
"internalId": 41,
"languageCode": "en",
"languageName": "English"
}
},
"sections": []
},
"committees": [],
"subsidies": "No",
"softSub": "",
"hardSub": "",
"validatorPath": null,
"reference": "IMUPT17"
},
"application": {
"internalId": 52,
"state": "APPROVED",
"companyName": "PicoSoft",
"codeName": "43bru532x8av9nxez5mi",
"subregion": "Ariana",
"legalForm": "SARL",
"registrationNumber": "45215455",
"taxIdentification": "455255656",
"belongToGroup": false,
"group": "",
"corpPurpose": "",
"hq": {
"address": "",
"email": "",
"website": "",
"phone": "",
"fax": ""
},
"pu": {
"address": "",
"email": "",
"website": "",
"phone": "",
"fax": ""
},
"cpFullName": "",
"cpFunction": "",
"dc": "",
"creationDate": 983746800000,
"startingActivityDate": 983746800000,
"sc": {
"amount": 0,
"national": 0,
"international": 0
},
"mainActivity": {
"internalId": 53,
"code": "60",
"title": "Programming and broadcasting activities",
"parent": {
"internalId": 10,
"code": "J",
"title": "Information and communication"
}
},
"ipm": "",
"esit": null,
"mainMarket": "",
"employmentNumber": 25,
"currency": {
"internalId": 143,
"currencyCode": "TND",
"currencyName": "Tunisian Dinar"
},
"country": {
"internalId": 224,
"a3Code": "TUN",
"a2Code": "TN",
"countryName": "Tunisia",
"nativeCountryName": "Tunisia"
},
"reference": "IMUPT17_52"
},
"decision": null,
"reference": "IMUPT17_60",
"instanceName": "Report"
},
{
"internalId": 62,
"state": "DIAGNOSIS_APPROVAL",
"project": {
"internalId": 25,
"acronym": "IMUPT",
"label": "IMUP216",
"comment": "",
"sap": "58",
"startingDate": 1488841200000,
"endingDate": 1553209200000,
"currency": {
"internalId": 143,
"currencyCode": "TND",
"currencyName": "Tunisian Dinar"
},
"budget": 250000000,
"defaultFrReportModelSet": {
"reference": "Sdr9r_fr.pdf",
"comment": "",
"active": false,
"expertPath": "C:\\pmn\\files\\a21f8c87-eae9-4c04-b00d-41b3087df602\\srd9rTestFR21_08_2017.pdf",
"validatorPath": "C:\\pmn\\files\\a21f8c87-eae9-4c04-b00d-41b3087df602\\srd9rTestFR21_08_2017.pdf",
"tuPath": "C:\\pmn\\files\\a21f8c87-eae9-4c04-b00d-41b3087df602\\srd9rTestFR21_08_2017.pdf",
"bmnPath": "C:\\pmn\\files\\a21f8c87-eae9-4c04-b00d-41b3087df602\\srd9rTestFR21_08_2017.pdf",
"locale": {
"internalId": 2,
"language": {
"internalId": 48,
"languageCode": "fr",
"languageName": "French"
}
},
"sections": []
},
"defaultEnReportModelSet": {
"reference": "Sdr9r.pdf",
"comment": "",
"active": false,
"expertPath": "C:\\pmn\\files\\200bba69-1be5-4640-b9e7-47f0d919145f\\srd9rTest.pdf",
"validatorPath": "C:\\pmn\\files\\200bba69-1be5-4640-b9e7-47f0d919145f\\srd9rTest.pdf",
"tuPath": "C:\\pmn\\files\\200bba69-1be5-4640-b9e7-47f0d919145f\\srd9rTest.pdf",
"bmnPath": "C:\\pmn\\files\\200bba69-1be5-4640-b9e7-47f0d919145f\\srd9rTest.pdf",
"locale": {
"internalId": 1,
"language": {
"internalId": 41,
"languageCode": "en",
"languageName": "English"
}
},
"sections": []
},
"committees": [],
"subsidies": "No",
"softSub": "",
"hardSub": "",
"validatorPath": null,
"reference": "IMUPT17"
},
"application": {
"internalId": 54,
"state": "APPROVED",
"companyName": "Telnet",
"codeName": "djw1q2nbtanec4gtzw7b9",
"subregion": "Ariana",
"legalForm": "SARL",
"registrationNumber": "45214455",
"taxIdentification": "55455",
"belongToGroup": true,
"group": "Telnet",
"corpPurpose": "",
"hq": {
"address": "",
"email": "",
"website": "",
"phone": "",
"fax": ""
},
"pu": {
"address": "",
"email": "",
"website": "",
"phone": "",
"fax": ""
},
"cpFullName": "",
"cpFunction": "",
"dc": "",
"creationDate": null,
"startingActivityDate": null,
"sc": {
"amount": 0,
"national": 0,
"international": 0
},
"mainActivity": {
"internalId": 43,
"code": "47",
"title": "Retail trade except of motor vehicles and motorcycles",
"parent": {
"internalId": 7,
"code": "G",
"title": "Wholesale and retail trade; repair of motor vehicles and motorcycles"
}
},
"ipm": "",
"esit": null,
"mainMarket": "",
"employmentNumber": 520,
"currency": {
"internalId": 143,
"currencyCode": "TND",
"currencyName": "Tunisian Dinar"
},
"country": {
"internalId": 224,
"a3Code": "TUN",
"a2Code": "TN",
"countryName": "Tunisia",
"nativeCountryName": "Tunisia"
},
"reference": "IMUPT17_54"
},
"decision": null,
"reference": "IMUPT17_62",
"instanceName": "Report"
},
{
"internalId": 61,
"state": "DIAGNOSIS_APPROVAL",
"project": {
"internalId": 25,
"acronym": "IMUPT",
"label": "IMUP216",
"comment": "",
"sap": "58",
"startingDate": 1488841200000,
"endingDate": 1553209200000,
"currency": {
"internalId": 143,
"currencyCode": "TND",
"currencyName": "Tunisian Dinar"
},
"budget": 250000000,
"defaultFrReportModelSet": {
"reference": "Sdr9r_fr.pdf",
"comment": "",
"active": false,
"expertPath": "C:\\pmn\\files\\a21f8c87-eae9-4c04-b00d-41b3087df602\\srd9rTestFR21_08_2017.pdf",
"validatorPath": "C:\\pmn\\files\\a21f8c87-eae9-4c04-b00d-41b3087df602\\srd9rTestFR21_08_2017.pdf",
"tuPath": "C:\\pmn\\files\\a21f8c87-eae9-4c04-b00d-41b3087df602\\srd9rTestFR21_08_2017.pdf",
"bmnPath": "C:\\pmn\\files\\a21f8c87-eae9-4c04-b00d-41b3087df602\\srd9rTestFR21_08_2017.pdf",
"locale": {
"internalId": 2,
"language": {
"internalId": 48,
"languageCode": "fr",
"languageName": "French"
}
},
"sections": []
},
"defaultEnReportModelSet": {
"reference": "Sdr9r.pdf",
"comment": "",
"active": false,
"expertPath": "C:\\pmn\\files\\200bba69-1be5-4640-b9e7-47f0d919145f\\srd9rTest.pdf",
"validatorPath": "C:\\pmn\\files\\200bba69-1be5-4640-b9e7-47f0d919145f\\srd9rTest.pdf",
"tuPath": "C:\\pmn\\files\\200bba69-1be5-4640-b9e7-47f0d919145f\\srd9rTest.pdf",
"bmnPath": "C:\\pmn\\files\\200bba69-1be5-4640-b9e7-47f0d919145f\\srd9rTest.pdf",
"locale": {
"internalId": 1,
"language": {
"internalId": 41,
"languageCode": "en",
"languageName": "English"
}
},
"sections": []
},
"committees": [],
"subsidies": "No",
"softSub": "",
"hardSub": "",
"validatorPath": null,
"reference": "IMUPT17"
},
"application": {
"internalId": 53,
"state": "APPROVED",
"companyName": "LB Consulting",
"codeName": "ca9vovl30tg83k6zdunmi",
"subregion": "Ariana",
"legalForm": "SARL",
"registrationNumber": "7850026",
"taxIdentification": "459663",
"belongToGroup": false,
"group": "",
"corpPurpose": "",
"hq": {
"address": "",
"email": "",
"website": "",
"phone": "",
"fax": ""
},
"pu": {
"address": "",
"email": "",
"website": "",
"phone": "",
"fax": ""
},
"cpFullName": "",
"cpFunction": "",
"dc": "",
"creationDate": null,
"startingActivityDate": null,
"sc": {
"amount": 0,
"national": 0,
"international": 0
},
"mainActivity": {
"internalId": 47,
"code": "52",
"title": "Warehousing and support activities for transportation",
"parent": {
"internalId": 8,
"code": "H",
"title": "Transportation and storage"
}
},
"ipm": "",
"esit": null,
"mainMarket": "",
"employmentNumber": 600,
"currency": {
"internalId": 143,
"currencyCode": "TND",
"currencyName": "Tunisian Dinar"
},
"country": {
"internalId": 224,
"a3Code": "TUN",
"a2Code": "TN",
"countryName": "Tunisia",
"nativeCountryName": "Tunisia"
},
"reference": "IMUPT17_53"
},
"decision": null,
"reference": "IMUPT17_61",
"instanceName": "Report"
},
答案 0 :(得分:0)
如果我理解正确,我认为你想要的是从你的响应对象中提取project
密钥。如果我没有错,那么你所分享的对象将成为大多数具有project
关键属性的对象数组。
如果您正在寻找上述假设,那么这可能是一个可能的解决方案。
var data = [{
"internalId": 60,
"state": "DIAGNOSIS_APPROVAL",
"project": {
"internalId": 25,
"acronym": "IMUPT",
"label": "IMUP216",
"comment": "",
"sap": "58",
"startingDate": 1488841200000,
"endingDate": 1553209200000,
"currency": {
"internalId": 143,
"currencyCode": "TND",
"currencyName": "Tunisian Dinar"
},
"budget": 250000000,
"defaultFrReportModelSet": {
"reference": "Sdr9r_fr.pdf",
"comment": "",
"active": false,
"expertPath": "",
"validatorPath": "",
"tuPath": "",
"bmnPath": "",
"locale": {
"internalId": 2,
"language": {
"internalId": 48,
"languageCode": "fr",
"languageName": "French"
}
},
"sections": []
},
"defaultEnReportModelSet": {
"reference": "Sdr9r.pdf",
"comment": "",
"active": false,
"expertPath": "C:\\pmn\\files\\200bba69-1be5-4640-b9e7-47f0d919145f\\srd9rTest.pdf",
"validatorPath": "",
"tuPath": "",
"bmnPath": "",
"locale": {
"internalId": 1,
"language": {
"internalId": 41,
"languageCode": "en",
"languageName": "English"
}
},
"sections": []
},
"committees": [],
"subsidies": "No",
"softSub": "",
"hardSub": "",
"validatorPath": null,
"reference": "IMUPT17"
},
"application": {
"internalId": 52,
"state": "APPROVED",
"companyName": "PicoSoft",
"codeName": "43bru532x8av9nxez5mi",
"subregion": "Ariana",
"legalForm": "SARL",
"registrationNumber": "45215455",
"taxIdentification": "455255656",
"belongToGroup": false,
"group": "",
"corpPurpose": "",
"hq": {
"address": "",
"email": "",
"website": "",
"phone": "",
"fax": ""
},
"pu": {
"address": "",
"email": "",
"website": "",
"phone": "",
"fax": ""
},
"cpFullName": "",
"cpFunction": "",
"dc": "",
"creationDate": 983746800000,
"startingActivityDate": 983746800000,
"sc": {
"amount": 0,
"national": 0,
"international": 0
},
"mainActivity": {
"internalId": 53,
"code": "60",
"title": "Programming and broadcasting activities",
"parent": {
"internalId": 10,
"code": "J",
"title": "Information and communication"
}
},
"ipm": "",
"esit": null,
"mainMarket": "",
"employmentNumber": 25,
"currency": {
"internalId": 143,
"currencyCode": "TND",
"currencyName": "Tunisian Dinar"
},
"country": {
"internalId": 224,
"a3Code": "TUN",
"a2Code": "TN",
"countryName": "Tunisia",
"nativeCountryName": "Tunisia"
},
"reference": "IMUPT17_52"
},
"decision": null,
"reference": "IMUPT17_60",
"instanceName": "Report"
},
{
"internalId": 60,
"state": "DIAGNOSIS_APPROVAL",
"project": {
"internalId": 5675676,
"acronym": "IMUPT",
"label": "IMUP216",
"comment": "",
"sap": "58",
"startingDate": 1488841200000,
"endingDate": 1553209200000,
"currency": {
"internalId": 143,
"currencyCode": "TND",
"currencyName": "Tunisian Dinar"
},
"budget": 250000000,
"defaultFrReportModelSet": {
"reference": "Sdr9r_fr.pdf",
"comment": "",
"active": false,
"expertPath": "",
"validatorPath": "",
"tuPath": "",
"bmnPath": "",
"locale": {
"internalId": 2,
"language": {
"internalId": 48,
"languageCode": "fr",
"languageName": "French"
}
},
"sections": []
},
"defaultEnReportModelSet": {
"reference": "Sdr9r.pdf",
"comment": "",
"active": false,
"expertPath": "C:\\pmn\\files\\200bba69-1be5-4640-b9e7-47f0d919145f\\srd9rTest.pdf",
"validatorPath": "",
"tuPath": "",
"bmnPath": "",
"locale": {
"internalId": 1,
"language": {
"internalId": 41,
"languageCode": "en",
"languageName": "English"
}
},
"sections": []
},
"committees": [],
"subsidies": "No",
"softSub": "",
"hardSub": "",
"validatorPath": null,
"reference": "IMUPT17"
},
"application": {
"internalId": 980980908,
"state": "APPROVED",
"companyName": "PicoSoft",
"codeName": "43bru532x8av9nxez5mi",
"subregion": "Ariana",
"legalForm": "SARL",
"registrationNumber": "45215455",
"taxIdentification": "455255656",
"belongToGroup": false,
"group": "",
"corpPurpose": "",
"hq": {
"address": "",
"email": "",
"website": "",
"phone": "",
"fax": ""
},
"pu": {
"address": "",
"email": "",
"website": "",
"phone": "",
"fax": ""
},
"cpFullName": "",
"cpFunction": "",
"dc": "",
"creationDate": 983746800000,
"startingActivityDate": 983746800000,
"sc": {
"amount": 0,
"national": 0,
"international": 0
},
"mainActivity": {
"internalId": 53,
"code": "60",
"title": "Programming and broadcasting activities",
"parent": {
"internalId": 10,
"code": "J",
"title": "Information and communication"
}
},
"ipm": "",
"esit": null,
"mainMarket": "",
"employmentNumber": 25,
"currency": {
"internalId": 143,
"currencyCode": "TND",
"currencyName": "Tunisian Dinar"
},
"country": {
"internalId": 224,
"a3Code": "TUN",
"a2Code": "TN",
"countryName": "Tunisia",
"nativeCountryName": "Tunisia"
},
"reference": "IMUPT17_52"
},
"decision": null,
"reference": "IMUPT17_60",
"instanceName": "Report"
}
]
var project=[];
for(var i=0;i<data.length;i++){
for(var j=0;j<Object.entries(data[i]).length;j++){
checkForData(Object.entries(data[i])[j][0]);
}
}
console.log(project);
function checkForData(value){
if(value === "project"){
project.push(Object.entries(data[i])[j][1]);
}
}