# VBA-JSON-2025 **Repository Path**: hlookup/VBA-JSON-2025 ## Basic Information - **Project Name**: VBA-JSON-2025 - **Description**: vba-json的增强版本,直接后期绑定字典之类 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-31 - **Last Updated**: 2026-03-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 来源于https://github.com/SanbiVN/VBA-JSON-2025 该版本是基于VBA-JSON增强版 一、增加了 JSON 解析选项(原版没有这些接口) 这个版本新增了很多 Property Let: ``` Public Property Let setCompareMode(b As Boolean) Public Property Let setAllowUnquotedKeys(b As Boolean) Public Property Let setUseDoubleForLargeNumbers(b As Boolean) Public Property Let setEscapeSolidus(b As Boolean) ``` 这些用于动态修改: ``` JsonOptions.CompareMode JsonOptions.AllowUnquotedKeys JsonOptions.UseDoubleForLargeNumbers JsonOptions.EscapeSolidus ``` 原仓库写法: ``` JsonConverter.JsonOptions.AllowUnquotedKeys = True ``` 而你这个版本变成: ``` setAllowUnquotedKeys True ``` ✔ 说明这个版本做了 接口封装优化 二、Dictionary 创建方式被改了(最大区别) 原版: ``` Set json_ParseObject = New Dictionary ``` 必须引用: Microsoft Scripting Runtime 你这个版本: ``` Set jsonParseObject = Interaction.CreateObject("Scripting.Dictionary") ``` 这是 晚期绑定版本。 优点: ✔ 不需要勾选引用 ✔ 换电脑不会报错 ✔ VBA / VB6 都能用 这是你之前想要解决的问题。 三、增加了 removeObjectKeys 函数 原版 没有: ``` Public Function removeObjectKeys(ByVal dict As Object ...) ``` 功能是: ``` {"a":1,"b":2} ``` 转成: 1,2 即 只输出值,不输出 key。 四、jsonParseObject 实现方式不同 原版写法: ``` Set json_ParseObject = New Dictionary json_ParseObject.CompareMode = TextCompare ``` 你这个版本: ``` Set jsonParseObject = Interaction.CreateObject("Scripting.Dictionary") jsonParseObject.CompareMode = -JsonOptions.CompareMode ``` 多了: ``` JsonOptions.CompareMode ``` 控制: BinaryCompare / TextCompare 五、字符串解析增强(支持 ' 单引号) 原版只支持: "abc" 你这个版本支持: 'abc' 代码: ``` Case """", "'": vv = jsonParseString(vv) ``` 这是 非标准 JSON 扩展。 六、StringBuffer 被引入 这个版本大量使用: Dim jBuffer As New StringBuffer 原版是: Dim json_Buffer As String 说明: 这个版本依赖 另一个类: StringBuffer.cls 优点: ✔ 拼接字符串速度快 ✔ 减少内存复制 七、jsonStringIsLargeNumber 有 bug 这里有明显问题: json_Length = lJson 正确应该是: json_Length = Len(tJson) 否则会导致 大数字判断错误。 八、增加了 UTC 时间转换模块 后半部分: VBA-UTC v1.0.6 UtcConverter 这是 另一个项目: VBA-UtcConverter 原仓库只是 引用它, 而你这个版本是 直接合并进一个文件。 优点: ✔ 不需要再导入 UtcConverter.bas 九、总结(和原版的核心差异) 项目 原版 你这个版本 Dictionary Early Binding Late Binding JSON key 必须双引号 支持单引号 JSON Options 直接访问 Property封装 String拼接 String StringBuffer removeObjectKeys ❌ ✔ UtcConverter 单独模块 已合并 大数字判断 正常 有 bug # VBA-JSON JSON conversion and parsing for VBA (Windows and Mac Excel, Access, and other Office applications). --------------------------------------------------------------------------- ### Last Update (2025) - Fixed parse number - Fixed decode \xXX for jsonParseString - Use StringBuffer (Cristian Buse) - [VBA-StringBuffer](https://github.com/cristianbuse/VBA-StringBuffer) - Recommended use Dictionary (Cristian Buse) - [VBA-FastDictionary](https://code.google.com/p/vba-json/](https://github.com/cristianbuse/VBA-FastDictionary)) It is recommended to move all code into Class module to reduce memory load, when not using Json parsing process. --------------------------------------------------------------------------- It grew out of the excellent project [vba-json](https://code.google.com/p/vba-json/), with additions and improvements made to resolve bugs and improve performance (as part of [VBA-Web](https://github.com/VBA-tools/VBA-Web)). Tested in Windows Excel 2013 and Excel for Mac 2011, but should apply to 2007+. - For Windows-only support, include a reference to "Microsoft Scripting Runtime" - For Mac and Windows support, include [VBA-Dictionary](https://github.com/VBA-tools/VBA-Dictionary) Donate # Examples ```vb Dim Json As Object Set Json = JsonConverter.ParseJson("{""a"":123,""b"":[1,2,3,4],""c"":{""d"":456}}") ' Json("a") -> 123 ' Json("b")(2) -> 2 ' Json("c")("d") -> 456 Json("c")("e") = 789 Debug.Print JsonConverter.ConvertToJson(Json) ' -> "{"a":123,"b":[1,2,3,4],"c":{"d":456,"e":789}}" Debug.Print JsonConverter.ConvertToJson(Json, Whitespace:=2) ' -> "{ ' "a": 123, ' "b": [ ' 1, ' 2, ' 3, ' 4 ' ], ' "c": { ' "d": 456, ' "e": 789 ' } ' }" ``` ```vb ' Advanced example: Read .json file and load into sheet (Windows-only) ' (add reference to Microsoft Scripting Runtime) ' {"values":[{"a":1,"b":2,"c": 3},...]} Dim FSO As New FileSystemObject Dim JsonTS As TextStream Dim JsonText As String Dim Parsed As Dictionary ' Read .json file Set JsonTS = FSO.OpenTextFile("example.json", ForReading) JsonText = JsonTS.ReadAll JsonTS.Close ' Parse json to Dictionary ' "values" is parsed as Collection ' each item in "values" is parsed as Dictionary Set Parsed = JsonConverter.ParseJson(JsonText) ' Prepare and write values to sheet Dim Values As Variant ReDim Values(Parsed("values").Count, 3) Dim Value As Dictionary Dim i As Long i = 0 For Each Value In Parsed("values") Values(i, 0) = Value("a") Values(i, 1) = Value("b") Values(i, 2) = Value("c") i = i + 1 Next Value Sheets("example").Range(Cells(1, 1), Cells(Parsed("values").Count, 3)) = Values ``` ## Options VBA-JSON includes a few options for customizing parsing/conversion if needed: - __UseDoubleForLargeNumbers__ (Default = `False`) VBA only stores 15 significant digits, so any numbers larger than that are truncated. This can lead to issues when BIGINT's are used (e.g. for Ids or Credit Cards), as they will be invalid above 15 digits. By default, VBA-JSON will use `String` for numbers longer than 15 characters that contain only digits, use this option to use `Double` instead. - __AllowUnquotedKeys__ (Default = `False`) The JSON standard requires object keys to be quoted (`"` or `'`), use this option to allow unquoted keys. - __EscapeSolidus__ (Default = `False`) The solidus (`/`) is not required to be escaped, use this option to escape them as `\/` in `ConvertToJson`. ```VB.net JsonConverter.JsonOptions.EscapeSolidus = True ``` ## Installation 1. Download the [latest release](https://github.com/VBA-tools/VBA-JSON/releases) 2. Import `JsonConverter.bas` into your project (Open VBA Editor, `Alt + F11`; File > Import File) 3. Add `Dictionary` reference/class - For Windows-only, include a reference to "Microsoft Scripting Runtime" - For Windows and Mac, include [VBA-Dictionary](https://github.com/VBA-tools/VBA-Dictionary) ## Resources - [Tutorial Video (Red Stapler)](https://youtu.be/CFFLRmHsEAs)