MIT License

项目介绍

VBA-tools/VBA-JSON 是一个托管在 GitHub 上的开源项目,主要使用 Visual Basic 编写,采用 MIT License 许可证,目前获得 2.1k 个 Star、624 次 Fork。

仓库全名
VBA-tools/VBA-JSON
开源许可证
MIT License
Star 数
2.1k
Fork 数
624
未关闭 Issue
119

README 摘要

VBA-JSON JSON conversion and parsing for VBA (Windows and Mac Excel, Access, and other Office applications). It grew out of the excellent project vba-json, with additions and improvements made to resolve bugs and improve performance (as part of 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…

完整内容见 GitHub 原始 README 或本页 。

常见问题

VBA-JSON 用什么语言开发?

主要使用 Visual Basic 编写,采用 MIT License 许可证,目前有 2.1k 个 Star。

VBA-JSON 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 VBA-JSON 的源码?

可以直接克隆仓库:git clone https://github.com/VBA-tools/VBA-JSON.git,默认分支为 master;安装与运行步骤见仓库 README。

VBA-JSON 最近还在维护吗?

仓库最近一次更新为 2024年3月15日,当前有 119 个未关闭 Issue;Star 数为 2.1k,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

JSON conversion and parsing for VBA

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
3565
价值分
1484
活跃状态
活跃
暂无主题

语言占比

Visual Basic

Release

README

VBA-JSON

JSON conversion and parsing for VBA (Windows and Mac Excel, Access, and other Office applications). It grew out of the excellent project vba-json, with additions and improvements made to resolve bugs and improve performance (as part of 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
Donate

Examples

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  
'       }
'     }"
' 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.
JsonConverter.JsonOptions.EscapeSolidus = True

Installation

  1. Download the latest release
  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

Resources

评论

暂无评论