Page History
...
Syntax
Code Block |
---|
Result = SRP_JSONJson(Handle, "GETVALUEGetValue", Path, Default) |
Returns
A descendant's value if it was found, "" if not.
Parameters
Parameter | Description |
---|---|
Handle | Handle to a JSON Entity. Required. |
Path | A formatted string indicating the desired descendant. Required. |
Default | An alternative value to return if the descendant's value is null. Optional. If this argument is ommitted, then a null value will return "<null>". |
Remarks
The GETVALUE GetValue service returns the value of a descendant entity somewhere within the current JSON Entity Handle. If the descendant is an object or array, then you'll get the entire JSON string for that entity. Otherwise, you'll get the element's value without extraneous formatting (like quotes around strings).
...
Code Block |
---|
MenuJSON = SRP_JSONJson(ObjectHandle, "GETVALUEGetValue", "menu") |
If you want to get a child of menu, you separate each member name with a period, like so:
Code Block |
---|
ItemsJSON = SRP_JSONJson(ObjectHandle, "GETVALUEGetValue", "menu.items") |
If you want to get an element within an array, you use square brackets instead of periods. This is how we drill down directly to the twelfth element within the items array:
Code Block |
---|
ItemJSON = SRP_JSONJson(ObjectHandle, "GETVALUEGetValue", "menu.items[12]") |
And this is how we get the handle to the "label" member of the second item in the items array:
Code Block |
---|
Label = SRP_JSONJson(ObjectHandle, "GETVALUEGetValue", "menu.items[2].label") |
Important. The Path parameter is a convenient way to drill into a JSON document. It reserves five characters: period, left square bracket, right square bracket, left angle bracket, and right angle bracket. If the member you want to access uses one of these characters, you must escape them by doubling up. Here's an example of a JSON document with periods in the member names and how to access them.
Code Block |
---|
{ "first.name" : "John" "last.name" : "Doe" } // INCORRECT: This will get you "" because it will try to get "first" and then "name" Name = SRP_Json(ObjectHandle, "GetValue", "first.name") // CORRECT: This will get you "first.name" Name = SRP_Json(ObjectHandle, "GetValue", "first..name") |
Note |
---|
This service always returns JSON Strings or values. If you want to get the JSON Entity Handle, you need to use GETGet instead. |
Example
Code Block |
---|
// Test parsing an existing JSON string and then drilling down into specific values SampleJSON = '{"menu": {' SampleJSON := ' "header": "SVG Viewer",' SampleJSON := ' "items": [' SampleJSON := ' {"id": "Open"},' SampleJSON := ' {"id": "OpenNew", "label": "Open New"},' SampleJSON := ' null,' SampleJSON := ' {"id": "ZoomIn", "label": "Zoom In"},' SampleJSON := ' {"id": "ZoomOut", "label": "Zoom Out"},' SampleJSON := ' {"id": "OriginalView", "label": "Original View"},' SampleJSON := ' null,' SampleJSON := ' {"id": "Quality"},' SampleJSON := ' {"id": "Pause"},' SampleJSON := ' {"id": "Mute"},' SampleJSON := ' null,' SampleJSON := ' {"id": "Find", "label": "Find..."},' SampleJSON := ' {"id": "FindAgain", "label": "Find Again"},' SampleJSON := ' {"id": "Copy"},' SampleJSON := ' {"id": "CopyAgain", "label": "Copy Again"},' SampleJSON := ' {"id": "CopySVG", "label": "Copy SVG"},' SampleJSON := ' {"id": "ViewSVG", "label": "View SVG"},' SampleJSON := ' {"id": "ViewSource", "label": "View Source"},' SampleJSON := ' {"id": "SaveAs", "label": "Save As"},' SampleJSON := ' null,' SampleJSON := ' {"id": "Help"},' SampleJSON := ' {"id": "About", "label": "About Adobe CVG Viewer..."}' SampleJSON := ' ],' SampleJSON := ' "testbool": "true",' SampleJSON := ' "testint": "1234567890",' SampleJSON := ' "testreal": "1234567890.987654321"' SampleJSON := '}}' // Parse it, then grab some values If SRP_JSONJson(ObjectHandle, "PARSEParse", SampleJSON) EQ "" then TestValue = SRP_JSONJson(ObjectHandle, "GETVALUEGetValue", "menu.items[1].id") TestValue = SRP_JSONJson(ObjectHandle, "GETVALUEGetValue", "menu.items[12].label") TestValue = SRP_JSONJson(ObjectHandle, "GETVALUEGetValue", "menu.items[3]") TestValue = SRP_JSONJson(ObjectHandle, "GETVALUEGetValue", "menu.testbool") TestValue = SRP_JSONJson(ObjectHandle, "GETVALUEGetValue", "menu.testint") TestValue = SRP_JSONJson(ObjectHandle, "GETVALUEGetValue", "menu.testreal") SRP_JSONJson(ObjectHandle, "RELEASERelease") end |