Hi Alex,
The problem in LotusScript is that there isn't really such a thing as an Object in the same way there is in JavaScript. To get around this problem, the JSON class converts any JSON object strings into a JSONObject which is a class that is also defined in the library. This object contains three public methods. GetItem, AddItem and ItemList.
Taking the example you provided, here is how you could convert that string to an object and then access the parameters of the resultant object.
Sub Initialize
Dim exampleJSONStr As String<br/>
Dim oJSON As JSON<br/>
Dim resultObject As JSONObject<br/>
Dim itemList As Variant<br/>
<br/>
'// Get the example string to be converted into LotusScript objects<br/>
exampleJSONStr = |{"field1":"Name", "field2":"Title", "field3":"Age"}|<br/>
<br/>
'// Create a new instance of the JSON objects that is used to do the parsing<br/>
Set oJSON = New JSON()<br/>
<br/>
'// Call the parse method to parse the JSON string<br/>
Set resultObject = oJSON.Parse(exampleJSONStr)<br/>
<br/>
'// Now you can get the value for field2 by using the following<br/>
Print "The value of Field2 is : " & resultObject.GetItem("field2")<br/>
<br/>
'// Alternatively you can loop through all the items in the object <br/>
itemList = resultObject.ItemList<br/>
Forall x In itemList<br/>
Print "The value of " & Listtag(x) & " is " & x<br/>
End Forall<br/>
<br/>
End Sub
The result of runnig this code would be the following print statements:
The value of Field2 is : Title
The value of field1 is Name
The value of field2 is Title
The value of field3 is Age
I hope that helps.
If you have any suggestions for enhancements or find any bugs, please let me know.
Cheers
Alan