Adicionando uma string com aspas duplas a um arquivo no vba
Estou obtendo dados de uma API AQI da China, estou colocando alguns dados em um banco de dados do SQL Server e isso funciona apenas com dandy. Também decidi adicionar tudo o que foi retornado da API em um arquivo JSON para que eu possa acessá-lo mais tarde.
Sempre que tento anexar a string retornada pela API ao arquivo, recebo o erro "Chamada de procedimento ou argumento inválido"
Isto é o que eu fiz até agora:
Public Sub AddToJson(Jsonline As String)
Dim strfile As String
Dim fso As New FileSystemObject
Dim fsoStream As TextStream
Dim iexist As String
Dim stradd As String
strfile = "c:\JSON_AQI.json"
stradd = Replace(Jsonline, Chr(34), Chr(34) & Chr(34) & Chr(34) & Chr(34))
Debug.Print stradd
iexist = Dir(strfile)
'check if the file exists
If iexist = "" Then
'if it exists, open it and add the line
Set fsoStream = fso.CreateTextFile(strfile)
Else
'if it doesn't exist, create it and add the line
Set fsoStream = fso.OpenTextFile(strfile, ForAppending)
End If
fsoStream.WriteLine stradd
fsoStream.Close
Set fsoStream = Nothing
Set fso = Nothing
End Sub
É isso que eu passo como parâmetro Jsonline:
{"status":"ok","data":{"aqi":164,"idx":7130,"attributions":[{"name":"Hunan Environmental Protection Agency (????????)"},{"name":"China National Urban air quality real-time publishing platform (??????????????)"}],"city":{"geo":[33.8561,115.7831],"name":"sanguó lanshèng gong, Bozhou"},"dominentpol":"pm25","iaqi":{"co":{"v":14.8},"no2":{"v":24.7},"o3":{"v":45.9},"pm10":{"v":97},"pm25":{"v":164},"so2":{"v":5.1}},"time":{"s":"2017-04-06 04:00:00","tz":"+08:00","v":1491451200}}}
como você pode ver, tentei adicionar aspas duplas extras à sequência sem sucesso. Há mais alguma coisa que estou faltando?