2017-05-01 3 views
0

관련 질문 : 우리는 JSON 객체에서 이전 키를 모르는 경우 Trying to get lotusscript json reader(ls.snapps.JSONReader)

어떻게 우리가 키 이름을 반복 할 수 ? 배열이 아닌 경우.

{ "colorsArray":{ 
     "red":"#f00", 
     "green":"#0f0", 
     "blue":"#00f", 
     "cyan":"#0ff", 
     "magenta":"#f0f", 
     "yellow":"#ff0", 
     "black":"#000" , 
     ..... 
    } 
} 

vResult.Key가있는 것처럼?

답변

0

당신이 'colorsArray'을 반복하고 싶은 당신이 이런 식으로 뭔가 할 수 다음 키를 모를 경우 :

Dim jsonReader As JSONReader 
Dim vResults As Variant 
Dim vPieces As Variant, vResultData As variant 
Dim sJSON As String 
sJson= |{ "colorsArray":[{ 
    "red":"#f00", 
    "green":"#0f0", 
    "blue":"#00f", 
    "cyan":"#0ff", 
    "magenta":"#f0f", 
    "yellow":"#ff0", 
    "black":"#000" 
} 
]}| 

Set jsonReader = New JSONReader 
Set vResults = jsonReader.parse(sJson) 

Set vResultData = vResults.GetItemValue("colorsArray")  
ForAll vResult In vResultData.Items 
    Forall tmp In vResult.Items   
     Print "Key: " + ListTag(tmp) + " Value: " + tmp  
    End ForAll 
End ForAll 

을 그리고 검사 할 경우 몇 가지 주요 다음 함수를 작성 존재하는 경우 :

Function isKeyAvailable(items As Variant, keyName As String) As Boolean 
    If IsElement (items(keyName)) Then 
     isKeyAvailable = true 
    Else 
     isKeyAvailable = false 
    End If 
End Function 

키가있는 경우 다음 사항을 확인할 수 있습니다

... 
Set vResultData = vResults.GetItemValue("colorsArray")  
ForAll vResult In vResultData.Items 
    If isKeyAvailable(vResult.Items, "green") Then 
     Print "Exist" 
    Else 
     Print "Does not exist" 
    End If 
End ForAll 
... 

당신이 f를하지 않은 경우 amiliar LotusScript와의 목록과 링크는 당신을 도울 것입니다 :

https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/basic/LSAZ_WORKING_WITH_LISTS.html

+0

감사를이 대답합니다. sJson = | { "colorsArray": { "red": "# f00", "녹색": "# 0f0", "파란색": "# 00f"와 같은 JSON 객체의 경우에는 배열이 아닙니다. " "시안 ":"#의 0FF " "마젠타 ":"#의 f0f " "노란색 ":"#의 FF0 " "블랙 ":"# 000 " } } | 우리는 ListTag (vResult)를 사용하여 ForAll 루프의 키를 나열 할 수 있다고 생각합니까? 그것은 나를 위해 작동하지 않았다. – kris