如何通过 google 脚本 (gs)(按行)将整个 google 电子表格读取为文本文件

How to read entire google spreadsheet as a text file via google script (gs) (by rows)

我有一个 google sheet,其中 json 格式的文本位于随机单元格中,需要通过 google 应用程序脚本阅读。 有一些方法可以按列读取它,也可以将其作为实际插入不必要分号的数组读取。 请告知如何像 UrlFetchApp.fetch 和 JSON.parse 那样做,但要直接从行中的传播 sheet 中读取,跳过空单元格?例如。 A1 B1 C1 ... A2 B2 C2 ... 等(无空格)

function readJson(){
  const sh = SpreadsheetApp.getActive().getSheetByName("Sheet1")
  const allValues = sh.getDataRange().getValues()
  const arrJson = []
  allValues.forEach(row=>{
    row.filter(cell=>cell).forEach(cell=>{
      try{
        const json = JSON.parse(cell)
        arrJson.push(json)
      } catch(ignore){
        // JSON parse failed, probably not JSON
      }
    })
  })

  // arrJson contains all json data from cells in Sheet1
}