栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在VBA中将带双引号的字符串添加到文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在VBA中将带双引号的字符串添加到文件

实际上,接收到的JSON包含中文字符而不是

?
您发布的字符,应如下所示:

{    "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        }    }}

因此,您必须设置要明确附加为Unipre的代码片段的编码。我建议使用以下简单功能通过以下方式读取,写入和附加文本文件

scripting.FileSystemObject

Function ReadTextFile(sPath As String, lFormat As Long) As String    ' lFormat -2 - System default, -1 - Unipre, 0 - ASCII    With CreateObject("scripting.FileSystemObject").OpenTextFile(sPath, 1, False, lFormat)        ReadTextFile = ""        If Not .AtEndOfStream Then ReadTextFile = .ReadAll        .Close    End WithEnd FunctionSub WriteTextFile(sContent As String, sPath As String, lFormat As Long)    With CreateObject("scripting.FileSystemObject").OpenTextFile(sPath, 2, True, lFormat)        .Write sContent        .Close    End WithEnd SubSub AppendTextFile(sContent As String, sPath As String, lFormat As Long)    With CreateObject("scripting.FileSystemObject").OpenTextFile(sPath, 8, True, lFormat)        .Write sContent        .Close    End WithEnd Sub

因此,您可以通过调用附加字符串:

AppendTextFile Jsonline & vbCrLf, "C:JSON_AQI.json", -1


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/382162.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号