考虑我有一个像这样的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
错误。有什么问题?有什么办法可以解决吗?
答案 0 :(得分:3)
这有效:
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
以及结果输出: