0

我完成了向 API 发送请求并以 JSON 格式获得回复的宏。然后将结果返回给 Sheet("results")。我也在创建单独的日志文件。问题是输出不是标准的 JSON 格式,例如:

    {
        "title": "Example Schema",
        "type": "object",
        "properties": {
            "firstName": {
                "type": "string"
            },
            "lastName": {
                "type": "string"
            },
            "age": {
                "description": "Age in years",
                "type": "integer",
                "minimum": 0
            }
        },
        "required": ["firstName", "lastName"]
    }

但确实有“excel required”双引号:

    "{
        ""title"": ""Example Schema"",
        ""type"": ""object"",
        ""properties"": {
            ""firstName"": {
                ""type"": ""string""
            },
            ""lastName"": {
                ""type"": ""string""
            },
            ""age"": {
                ""description"": ""Age in years"",
                ""type"": ""integer"",
                ""minimum"": 0
            }
        },
        ""required"": [""firstName"", ""lastName""]
    }"

我的宏看起来像(有点被截断):

'output path
Dim FF As Integer
    FF = FreeFile
Dim FilePath As String

   FilePath = ActiveWorkbook.Path & "\Log" & Format(Now(), "yyyymmdd") & ".txt"

Open FilePath For Append As FF

sJson = ""
'turncated here ...


ObjHttp.Open "POST", sURL, False
ObjHttp.setRequestHeader "Content-Type", "application/json"
ObjHttp.send (sJson)
xmlDoc.LoadXML (ObjHttp.responseText)

'log
 Dim LastRow As Long
 With ThisWorkbook.Sheets("Result")
      LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
 End With

Sheets("Result").Cells(LastRow + 1, 1) = Now()
Sheets("Result").Cells(LastRow + 1, 2) = ObjHttp.responseText

Write #FF, ObjHttp.responseText

Next i

Close #FF

End Sub

为了删除双引号,我需要更改什么?

提前谢谢了。

4

1 回答 1

0

这个用双引号代替单引号

Dim findChars, replaceChars As String

findChars = """"""

replaceChars = """"

Replace(ObjHttp.responseText, findChars, replaceChars)
于 2014-12-17T14:03:41.343 回答