Einhugur JSON Plugin III for Xojo |
|
JSONDocument.GetValueByPath Method
Executes JSON Pointer query on the document, returning the result as JSONPrimitive or nil.
Parameters
- path
- The path query to execute.
Returns
- EinhugurJSONIII.JSONPrimitive
- Result primitive or nil if nothing was found.
Remarks
A JSON Pointer is a list of zero-to-many tokens, each prefixed by /. Each token can be a string or a number. For example, given a JSON:
{
"foo" : ["bar", "baz"],
"pi" : 3.1416
}
The following JSON Pointers resolve this JSON as:
1: “/foo” → [ “bar”, “baz” ]
2: “/foo/0" → "bar"
3: “/foo/1" → "baz"
4: ”/pi" → 3.1416
Note that, an empty JSON Pointer "" (zero token) resolves to the whole JSON.Example code:
var doc as EinhugurJSONIII.JSONDocument = new EinhugurJSONIII.JSONDocument()
var json as String = "{ ""hello"" : ""world"", ""t"" : true , ""f"" : false, ""n"": null, ""i"":123, ""pi"": 3.1416, ""a"":[1, 2, 3, 4] } "
if doc.Parse(json) then
var result as EinhugurJSONIII.JSONPrimitive = doc.GetValueByPath("/a/1")
if result <> nil then
MessageBox result.Int64Value.ToString()
end if
end if
See Also
JSONDocument Class