如何在 LotusScript 中遍历每个 JSON 的对象 属性
How do I iterate through each JSON's object property in LotusScript
假设我有一个这样的 JSON 对象
{
"someObject":
{
"Object_Name": "objName",
"Alternative_Name" : "altName",
"Alias_Name" : "alias"
}
}
如何使用 LotusScript 遍历 someObject 的每个 属性 并相应地获取键和值?到目前为止我已经试过了
Dim vResults As Variant
Dim vResultData As Variant
Dim jsonReader As New JSONReader
Set vResults = jsonReader.Parse(someObjectJSON.ToJSON())
Set vResultData = vResults.GetItemValue("someObject")
ForAll vResult In vResultData.Items
ForAll tmp In vResult.Items
Print "Key: " + ListTag(tmp) + " Value: " + tmp
End ForAll
End ForAll
但不幸的是它不起作用并且在 forAll 循环中给我 ObjectVariable not set
错误。有什么问题?有什么办法解决吗?
这个有效:
ForAll item In vResultData.Items
Print "Key: " + ListTag(item) + " Value: " + item
End ForAll
完整示例如下:
Option Declare
Use "ls.snapps.JSONReader"
Sub Initialize
Dim sJSON As String
Dim jsonReader As JSONReader
Dim vResults As Variant
Dim vResultData As Variant
Set jsonReader = New JSONReader
sJSON = |{
"someObject": {
"Object_Name": "objName",
"Alternative_Name": "altName",
"Alias_Name": "alias"
}
}|
Set vResults = jsonReader.Parse(sJSON)
Set vResultData = vResults.GetItemValue("someObject")
ForAll item In vResultData.Items
Print "Key: " + ListTag(item) + " - Value: " + item
End ForAll
End Sub
和结果输出:
假设我有一个这样的 JSON 对象
{
"someObject":
{
"Object_Name": "objName",
"Alternative_Name" : "altName",
"Alias_Name" : "alias"
}
}
如何使用 LotusScript 遍历 someObject 的每个 属性 并相应地获取键和值?到目前为止我已经试过了
Dim vResults As Variant
Dim vResultData As Variant
Dim jsonReader As New JSONReader
Set vResults = jsonReader.Parse(someObjectJSON.ToJSON())
Set vResultData = vResults.GetItemValue("someObject")
ForAll vResult In vResultData.Items
ForAll tmp In vResult.Items
Print "Key: " + ListTag(tmp) + " Value: " + tmp
End ForAll
End ForAll
但不幸的是它不起作用并且在 forAll 循环中给我 ObjectVariable not set
错误。有什么问题?有什么办法解决吗?
这个有效:
ForAll item In vResultData.Items
Print "Key: " + ListTag(item) + " Value: " + item
End ForAll
完整示例如下:
Option Declare
Use "ls.snapps.JSONReader"
Sub Initialize
Dim sJSON As String
Dim jsonReader As JSONReader
Dim vResults As Variant
Dim vResultData As Variant
Set jsonReader = New JSONReader
sJSON = |{
"someObject": {
"Object_Name": "objName",
"Alternative_Name": "altName",
"Alias_Name": "alias"
}
}|
Set vResults = jsonReader.Parse(sJSON)
Set vResultData = vResults.GetItemValue("someObject")
ForAll item In vResultData.Items
Print "Key: " + ListTag(item) + " - Value: " + item
End ForAll
End Sub
和结果输出: