是否有适用于 VB6/VBA 的 JSON 解析器? [英] Is There a JSON Parser for VB6 / VBA?
问题描述
我正在尝试使用 VB6 中的 Web 服务.我控制的服务当前可以返回 SOAP/XML 消息或 JSON.我很难弄清楚 VB6 的 SOAP 类型(版本 1)是否可以处理返回的 object
- 而不是像 string
、int<这样的简单类型/code> 等.到目前为止,我无法弄清楚我需要做什么才能让 VB6 使用返回的对象.
I am trying to consume a web service in VB6. The service - which I control - currently can return a SOAP/XML message or JSON. I am having a really difficult time figuring out if VB6's SOAP type (version 1) can handle a returned object
- as opposed to simple types like string
, int
, etc. So far I cannot figure out what I need to do to get VB6 to play with returned objects.
所以我想我可以将 Web 服务中的响应序列化为 JSON 字符串.VB6 是否存在 JSON 解析器?
So I thought I might serialize the response in the web service as a JSON string. Does a JSON parser exist for VB6?
推荐答案
查看 JSON.org- 许多不同语言的 JSON 解析器的日期列表(见主页底部).在撰写本文时,您将在那里看到几个不同的 JSON 解析器的链接,但只有一个用于 VB6/VBA(其他是 .NET):
Check out JSON.org for an up-to-date list (see bottom of main page) of JSON parsers in many different languages. As of the time of this writing, you'll see a link to several different JSON parsers there, but only one is for VB6/VBA (the others are .NET):
- 当我尝试下载 zip 文件时,Windows 表示数据已损坏.但是,我能够使用 7-zip 来提取文件.事实证明,zip 文件中的主文件夹"未被 Windows 识别为文件夹,通过 7-zip 可以看到该主文件夹"的内容,因此您可以打开它,然后相应地提取文件.
这个 VB JSON 库的实际语法非常简单:
- When I tried to download the zip file, Windows said the data was corrupt. However, I was able to use 7-zip to pull the files out. It turns out that the main "folder" in the zip file isn't recognized as a folder by Windows, by 7-zip can see the contents of that main "folder," so you can open that up and then extract the files accordingly.
The actual syntax for this VB JSON library is really simple:
Dim p As Object
Set p = JSON.parse(strFormattedJSON)
'Print the text of a nested property '
Debug.Print p.Item("AddressClassification").Item("Description")
'Print the text of a property within an array '
Debug.Print p.Item("Candidates")(4).Item("ZipCode")
这篇关于是否有适用于 VB6/VBA 的 JSON 解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!