http://hubtest.atspace.cc/json.htmlGET値は、上記のJSONレスポンスではJavaScript
に、私は別のURLの一部として使用するLAST objectID値を取得する必要があります。 JavaScriptを使ってこれを行う最善の方法は何ですか?
正規表現で試してみましたが、あまりにも面倒です。私は簡単な方法があると仮定しています。
http://hubtest.atspace.cc/json.htmlGET値は、上記のJSONレスポンスではJavaScript
に、私は別のURLの一部として使用するLAST objectID値を取得する必要があります。 JavaScriptを使ってこれを行う最善の方法は何ですか?
正規表現で試してみましたが、あまりにも面倒です。私は簡単な方法があると仮定しています。
試行でありますソース上のJSON.parse(...)
(それは文字通りJSONなので)、オブジェクトリテラルのように扱います。
var array = JSON.parse(...)
の配列を使用できるので、array[array.length - 1].objectID
を取得してください。
は基本的に、
var lastObj = a[a.length - 1];
戻り、アレイ内の最後のオブジェクトをバックアップします。次に、そのプロパティにアクセスできます。
var objectID = lastObj['objectId'];
ショートカット
var objectID = a[a.length - 1]['objectId'];
Array.length
戻り配列中の全要素、及び数はゼロベースであるため、長さオフに1を取ると、最後のインデックスを取得します。例えば。 6つの要素を持つアレイの場合、最後の要素のインデックスは5(6-1)= 5)
ワーキングスニペットは、Iトリミングオブジェクトダウン2.
var a = [{
"type": "PAPER",
"data": null,
"proceedingNumber": "IPR2016-00546",
"petitionId": "1463786",
"mimeType": null,
"fileName": "'306 Petition.pdf",
"partyGroupType": "petitioner",
"proceedingPartyGroupId": null,
"availability": "PUBLIC",
"documentName": "Petition For Inter Partes Review U.S. Patent No. 8,772,306",
"pageCount": "0",
"documentType": "16",
"exhibitNumber": null,
"petitionVO": null,
"institutionDecisionVO": null,
"terminationDecisionVO": null,
"proceedingReqType": null,
"proceedingReqTypeId": null,
"proceedingReqTypeStatusId": null,
"appealId": null,
"internalUserProxyEmail": null,
"proceedingId": "1463786",
"paperType": "16",
"documentTypeId": 16,
"customMotionTypeName": null,
"otherMotionType": null,
"objectId": "d29ya3NwYWNlOi8vU3BhY2VzU3RvcmUvNGVjOGFjMzQtODI5Yi00OTZhLTg0ZDItMDU2NTQzNmQ4NTI0OzEuMA==",
"objectType": null,
"artifactSubmissionId": "84644821",
"exhibitSequenceNumber": null,
"dateAdded": "02/02/2016",
"uploadStatus": null,
"expungedFlag": "N",
"deletedFlag": null,
"docVersionLabel": null,
"filingDate": "02/02/2016",
"proceedingArtifactId": "169264898",
"artifactNumber": "1",
"petitionState": null,
"patentNumber": null,
"fileSize": 0,
"submitterId": 11915,
"comment": null,
"createdbyAuthorName": null,
"disableSelect": null,
"employeeId": null,
"lockControlNo": 0,
"paperTypeName": "Petition",
"proceedingPartyId": null,
"filingParty": "petitioner",
"documentCategory": null,
"showExpungeAction": false,
"showUnExpungeAction": false,
"showDownloadLink": true,
"skipUploadTaskRecord": false,
"showEditLink": true,
"inputStream": null
}, {
"type": "PAPER",
"data": null,
"proceedingNumber": "IPR2016-00546",
"petitionId": "1463786",
"mimeType": null,
"fileName": "306 Exhibit List.pdf",
"partyGroupType": "petitioner",
"proceedingPartyGroupId": null,
"availability": "PUBLIC",
"documentName": "Exhibit List",
"pageCount": "0",
"documentType": "16",
"exhibitNumber": null,
"petitionVO": null,
"institutionDecisionVO": null,
"terminationDecisionVO": null,
"proceedingReqType": null,
"proceedingReqTypeId": null,
"proceedingReqTypeStatusId": null,
"appealId": null,
"internalUserProxyEmail": null,
"proceedingId": "1463786",
"paperType": "16",
"documentTypeId": 16,
"customMotionTypeName": null,
"otherMotionType": null,
"objectId": "d29ya3NwYWNlOi8vU3BhY2VzU3RvcmUvNDBhMjRjMmQtYWZkZi00OTdlLThkN2ItZGQ2ZTE5MmVjMWVkOzEuMA==",
"objectType": null,
"artifactSubmissionId": "84644822",
"exhibitSequenceNumber": null,
"dateAdded": "02/02/2016",
"uploadStatus": null,
"expungedFlag": "N",
"deletedFlag": null,
"docVersionLabel": null,
"filingDate": "02/02/2016",
"proceedingArtifactId": "169264900",
"artifactNumber": "2",
"petitionState": null,
"patentNumber": null,
"fileSize": 0,
"submitterId": 11915,
"comment": null,
"createdbyAuthorName": null,
"disableSelect": null,
"employeeId": null,
"lockControlNo": 0,
"paperTypeName": "Petition",
"proceedingPartyId": null,
"filingParty": "petitioner",
"documentCategory": null,
"showExpungeAction": false,
"showUnExpungeAction": false,
"showDownloadLink": true,
"skipUploadTaskRecord": false,
"showEditLink": true,
"inputStream": null
}]
console.log(a[a.length - 1]['objectId']);
この回答には、JSONの解析方法に関する情報が必要です。 OPがJSON出力を指していて、RegExを使用して目的のビットにアクセスする可能性があることに言及しています。 – JAAulde
これはうまくいったが、最初に解析しなければならなかった。 –