RESTful サービスからスプレッドシートに入力しようとしていますが、そのようなプロパティがない場合があるため、スプレッドシートに「未定義」が表示され、スクリプトが停止してエラーが発生します。どのように対処するか、または「未定義」の部分をスキップする方法についての手がかりがありません。
これはjsonのサンプルクエリです
{
"rel": "self",
"url": "https://www.sciencebase.gov/catalog/items?max=2&s=Search&q=project+
2009+WLCI&format=json&fields=title%2Csummary%2Cspatial%2Cfacets",
"total": 65,
"nextlink": {
"rel": "next",
"url": "https://www.sciencebase.gov/catalog/items?max=2&s=
Search&q=project+2009+WLCI&format=json&fields=title%2Csummary%2
Cspatial%2Cfacets&offset=2"
},
"items": [
{
"link": {
"rel": "self",
"url": "https://www.sciencebase.gov/catalog/item/
4f4e4ac3e4b07f02db67875f"
},
"id": "4f4e4ac3e4b07f02db67875f",
"title": "Decision-Making and Evaluation - Social and Economic
Evaluation Supporting Adaptive Management for WLCI",
"summary": "Provide information on the social and economic environment
for the WLCI area and provide context for the biological and physical
aspects of this project.",
"spatial": {
"representationalPoint": [
-108.585,
42.141
]
},
"facets": [
{
"startDate": "2007-10-01 00:00:00",
"projectStatus": "Active",
"facetName": "Project",
"_class": "ProjectFacet",
"active": true,
"className": "gov.sciencebase.catalog.item.facet.ProjectFacet",
"endDate": null,
"projectType": "Science",
"_embeddedClassName": "gov.sciencebase.catalog.item.facet.
ProjectFacet"
}
]
},
{
"link": {
"rel": "self",
"url": "https://www.sciencebase.gov/catalog/item
/4f4e4ac0e4b07f02db676d57"
},
"id": "4f4e4ac0e4b07f02db676d57",
"title": "Data and Information Management Products for the Wyoming
Landscape Conservation Initiative"
}
]
}
2 番目のアイテムにはタイトルしかなく、それ以降は何もないため、ループを使用してアイテムの概要やファセットなどを取得しようとすると、「未定義」になります。次のようなifステートメントを考えて使用してみました
if (parsedResponse.items[i].summary === "undefined") {
Do something here;
}
しかし、これはうまくいかないようです。私が試すことができる提案は大歓迎です。ありがとう