从 MS Access 解析 VBA 中的 JSON (US BLS)

2023-12-11

预先感谢您的帮助。

我正在使用 JSON VB6 解析器,可以在以下位置找到它:VB JSON 解析器

我有以下 JSON 响应(来自 BLS 网站,特别是此链接Here:

{“状态”:“REQUEST_SUCCEEDED”,“响应时间”:71,“消息”:[],“结果”:{ “系列”: [{"seriesID":"WPS012","data":[{"year":"2014","period":"M11","periodName":"11月","value":"153.6","脚注":[{"code":"P","text":"初步。所有索引均会在原始发布后四个月内进行修订。"}]},{"year":"2014","period":" M10","periodName":"10 月","value":"147.4","footnotes":[{"code":"P","text":"初步。所有索引均会在原始索引后四个月内进行修订"}]},{"year":"2014","period":"M09","periodName":"9 月","value":"146.5","footnotes":[{"code": "P","text":"初步。所有索引均会在原始发布后四个月内进行修订。"}]},{"year":"2014","period":"M08","periodName":"八月","value":"156.9","footnotes":[{"code":"P","text":"初步。所有索引均会在原始发布后四个月内进行修订。"}]},{ "year":"2014","period":"M07","periodName":"7 月","value":"156.4","footnotes":[{}]},{"year":"2014" ,"period":"M06","periodName":"6 月","value":"179.6","footnotes":[{}]},{"year":"2014","period":"M05 ","期间名称": "5 月","value":"205.4","footnotes":[{}]},{"year":"2014","period":"M04","periodName":"4 月","value" :"201.6","脚注":[{}]},{"year":"2014","period":"M03","periodName":"3 月","value":"188.1","脚注":[{}]},{"year":"2014","period":"M02","periodName":"二月","value":"180.2","footnotes":[{}]} ,{"year":"2014","period":"M01","periodName":"一月","value":"177.8","footnotes":[{}]},{"year":" 2013","period":"M12","periodName":"12 月","value":"183.2","footnotes":[{}]},{"year":"2013","period": "M11","periodName":"11 月","value":"180.4","footnotes":[{}]},{"year":"2013","period":"M10","periodName" :"10 月","value":"186.4","footnotes":[{}]},{"year":"2013","period":"M09","periodName":"9 月","value ":"197.1","footnotes":[{}]},{"year":"2013","period":"M08","periodName":"8 月","value":"222.2","脚注":[{}]},{"year":"2013","period":"M07","periodName":"7 月","value":"252.9","footnotes":[{}] },{"year":"2013","period":"M06","periodName":"6 月","value":"259.0","footnotes":[{}]},{"year": "2013","期间":"M05","p eriodName":"5 月","value":"263.7","footnotes":[{}]},{"year":"2013","period":"M04","periodName":"4 月", "value":"249.3","footnotes":[{}]},{"year":"2013","period":"M03","periodName":"3 月","value":"268.1" ,"footnotes":[{}]},{"year":"2013","period":"M02","periodName":"二月","value":"267.1","footnotes":[{ }]},{"year":"2013","period":"M01","periodName":"一月","value":"279.7","footnotes":[{}]},{"year ":"2012","period":"M12","periodName":"12 月","value":"283.2","footnotes":[{}]},{"year":"2012"," period":"M11","periodName":"11 月","value":"280.8","footnotes":[{}]},{"year":"2012","period":"M10", "periodName":"10 月","value":"286.7","footnotes":[{}]},{"year":"2012","period":"M09","periodName":"9 月" ,"value":"285.2","footnotes":[{}]},{"year":"2012","period":"M08","periodName":"8 月","value":"298.9 ","脚注":[{}]},{"year":"2012","period":"M07","periodName":"7月","value":"275.8","footnotes":[ {}]},{"year":"2012","period":"M06","periodName":"6 月","value":"226.9","footnotes":[{}]},{"年份":"2012","期间 d":"M05","periodName":"5 月","value":"233.7","footnotes":[{}]},{"year":"2012","period":"M04", "periodName":"4 月","value":"239.9","footnotes":[{}]},{"year":"2012","period":"M03","periodName":"3 月" ,"value":"243.6","footnotes":[{}]},{"year":"2012","period":"M02","periodName":"二月","value":"239.9 ","脚注":[{}]},{"year":"2012","period":"M01","periodName":"1月","value":"243.8","footnotes":[ {}]}]}] }}`

我能够使用解析器返回“status”、“responseTime”和“message”。除此之外(第二个花括号的开头)我什么也得不到。

下面是我尝试使用的代码:

Dim p As Object
Set p = JSON.parse(gbl_response)


'Print the text of a nested property '
Debug.Print p.Item("responseTime")
'Print the text of a property within an array '
Debug.Print p.Item("Results").Item("series").Item("seriesID")

p.Item("responseTime") 的打印有效并返回“71”,但是我在第二次打印尝试时收到“无效的调用过程或参数”错误。

在我的一生中,我四处寻找,但没有找到任何解决方案。我试过了this这看起来几乎相同,但可惜的是,我尝试在这里复制该解决方案,但它似乎不起作用。

谢谢您的帮助!


Public Const jsonSource As String = "{" & _
  """status"": ""REQUEST_SUCCEEDED"", " & _
  """responseTime"": 71, " & _
  """message"": [ " & _
  "], " & _
  """Results"": { " & _
    """series"": [ " & _
      "{ " & _
        """seriesID"": ""WPS012"", " & _
        """data"": [ " & _
          "{ " & _
            """year"": ""2014"", " & _
            """period"": ""M11"", " & _
            """periodName"": ""November"", " & _
            """value"": ""153.6"", " & _
            """footnotes"": [ " & _
              "{ " & _
                """code"": ""P"", " & _
                """text"": ""Preliminary. All indexes are subject to revision four months after original publication."" " & _
              "} " & _
            "] " & _
          "} " & _
        "] " & _
      "}]}}"

Sub JsonTest()
    Dim jsonData As Scripting.Dictionary
    Set jsonData = JSON.parse(jsonSource)

    Dim responseTime As String
    responseTime = jsonData("responseTime")

    Dim results As Scripting.Dictionary
    Set results = jsonData("Results")

    Dim series As Collection
    Set series = results("series")

    Dim seriesItem As Scripting.Dictionary
    For Each seriesItem In series
        Dim seriesId As String
        seriesId = seriesItem("seriesID")
        Debug.Print seriesId

        Dim data As Collection
        Set data = seriesItem("data")

        Dim dataItem As Scripting.Dictionary
        For Each dataItem In data
            Dim year As String
            year = dataItem("year")

            Dim period As String
            period = dataItem("period")

            Dim periodName As String
            periodName = dataItem("periodName")

            Dim value As String
            value = dataItem("value")

            Dim footnotes As Collection
            Set footnotes = dataItem("footnotes")

            Dim footnotesItem As Scripting.Dictionary
            For Each footnotesItem In footnotes
                Dim code As String
                code = footnotesItem("code")

                Dim text As String
                text = footnotesItem("text")

            Next footnotesItem
        Next dataItem
    Next seriesItem
End Sub

enter image description here

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 MS Access 解析 VBA 中的 JSON (US BLS) 的相关文章

随机推荐

  • Oracle SQL 对版本号进行排序

    在 Oracle 中 只需使用ORDER BY不对版本号进行排序 我的Version Number字段被声明为VARCHAR我无法改变它 例如 以下版本 1 20 1 9 1 18 1 13 1 5 1 11 2 0 1 8 1 3 1 2
  • 使用SFTP / RCurl创建远程目录

    是否可以使用 RCurl 包在 SFTP 站点上创建目录 我找到了sftp create dirs函数 但我找不到如何使用它的示例 我尝试设置ftp create missing dirs选项TRUE as in library RCurl
  • JavaScript 提升函数与函数变量

    这是我的 JavaScript 代码 console log a c b var a Hello World var b function console log B is called function c console log C i
  • AttributeError:构建逻辑回归模型时“str”对象没有属性“decode”[重复]

    这个问题在这里已经有答案了 我正在尝试建立一个逻辑回归模型 但它显示了AttributeError str object has no attribute decode 请帮我解决这个问题 该代码在 Datacamp 的服务器上完美运行 但
  • ValueError:解析日期时时间数据与格式不匹配

    当我尝试将字符串解析为日期时间时 我这样做 之前已导入日期时间 fecha 2 datetime strptime 22 01 2019 17 00 d m y H M 但是 我收到此错误 ValueError 时间数据 22 01 201
  • PHP 方法链接的好处?

    仍在 PHP OOP 训练轮上 这个问题可能属于失败博客网站 PHP 中的方法链有什么好处 我不确定这是否重要 但我将静态调用我的方法 例如 foo Bar get sysop gt set admin gt render 根据我的阅读 任
  • 从 GradientBoostingClassifier 中提取决策规则

    我已经解决了以下问题 如何提取梯度提升分类器的决策规则 如何从 scikit learn 决策树中提取决策规则 然而以上两个并没有解决我的目的 以下是我的查询 我需要使用gradientboostingclassifer在Python中构建
  • 为什么在输入n之前声明数组的大小为n,第一次有效,但第二次就不行了?

    我正在解决一个问题 在输入 n 的值之前 我将数组的大小声明为 n 它适用于第一个测试用例 但不适用于第二个测试用例 为什么 P S 我在网上找不到任何相关信息 这是代码片段 int n arr n cin gt gt n int n ar
  • 快速从 findObjectsInBackgroundWithBlock 获取数据

    我正在使用 Parse 从数据库中获取数据 当块 findObjectsInBackgroundWithBlock 被调用时 会传递一个数组 由于我只接收一行数据 因此它全部出现在数组的一个 0 部分中 那么我如何从该数组中获取所有位 这是
  • 正确的表格标题

    语义问题 如果我有一个基本上是一张大表的 HTML 页面 我应该使用什么元素作为标题 通常 您会使用h1用于页面标题 以及caption作为表格的标题 但是 如果表格是页面上唯一的内容怎么办 包括两者看起来有点傻 那我用一个h1并忘记cap
  • 未找到配置或 get/set 在 Angular 6 中已被弃用

    ng config global defaults styleExt scss 错误 找不到配置 ng set global defaults styleExt scss 错误 get set 已被弃用 取而代之的是 config 命令 已
  • PyQT5错误:无法找到或加载Qt平台插件xcb

    直到 为止Anaconda3 其中包含Python 3 4 已重新安装在我的RedHat 6 5工作站 我已经能够开发使用的Python应用程序PyQT5 重新安装后Anaconda我收到一条错误消息 无法找到或加载 Qt 平台插件 xcb
  • React 虚拟化下拉菜单被溢出剪切:隐藏

    我正在为我的表使用react virtualized 我想在单击单元格中的按钮时显示一个下拉菜单 问题是我的下拉菜单被表格的行高抑制 行高 40 行高度 200 我玩过css定位 但到目前为止没有任何效果 下拉菜单代码 div div
  • 具有线程的多上下文 CoreData

    UPDATE 我想问题是保存子上下文时父上下文没有更新 仍然需要帮助 我尝试过很多多上下文 父子 核心数据的例子 以前我的应用程序使用传统的数据存储方式 即我使用了一个OperationQueue 我从服务器获取数据并使用MOC保存到数据库
  • SQL Server 查找不同行之间的 datediff、总和

    我正在尝试构建一个查询来分析我们的时间跟踪系统中的数据 每次用户滑入或滑出时 它都会生成一行记录滑入时间以及 在场 或 场外 进入或退出 在用户 Joe Bloggs 的情况下 有 4 行 我想将其配对并计算 Joe Bloggs 在网站上
  • 出现异常“并非所有代码路径都返回值”

    您好 我有一个使用查询更新 MySQL 表的方法 我使用 MS Visual Studio 和 phpmyadmin 作为 SQL 客户端 Method public static Member updateMember string un
  • Maven无法连接到docker内的网络

    我正在尝试克隆一个 git 项目并执行以下操作mvn package在码头工人里面 但是maven无法连接网络下载依赖项 这是Dockerfile FROM java 8 FROM maven ADD id rsa root ssh id
  • 使用 Solrj / Spring Data Solr 实现标记和排除过滤器

    我正在尝试在字段上实现多选的 Solr Facet 搜索 举这个例子 http docs lucidworks com display solr Faceting Faceting LocalParametersforFaceting 我想
  • 删除sql中的重复项并相应修改关系表

    我有三张桌子 menu tab 有列 menu id menu description item tab 有列 item id item name item description item price menu has item有列 me
  • 从 MS Access 解析 VBA 中的 JSON (US BLS)

    预先感谢您的帮助 我正在使用 JSON VB6 解析器 可以在以下位置找到它 VB JSON 解析器 我有以下 JSON 响应 来自 BLS 网站 特别是此链接Here 状态 REQUEST SUCCEEDED 响应时间 71 消息 结果