|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > JSON - Parser > Parser-Operations > !Utility and Conversion > PSJ. - JSON Operations |
SPR Script Language
PSJ.GetLastResultW
Gets the last primary WSTRING result produced by the JSW library, returned as a standard STRING (UTF-8).
Intention
The PSJ.GetLastResultW command retrieves the most recent WSTRING result that was stored internally by the JSW library. Several commands, particularly those involved in serialization (like PSJ.ToString, PSJ.NodeToStr) or complex extraction (like PSJ.GetKeys), place their primary output into this internal storage via the W_JSON_HandleResultOutput helper. This command fetches that stored WSTRING and converts it into a standard SPR STRING (assuming UTF-8 encoding) for use in your script, optionally storing it in $$RES. See also PSJ.GetLastResultS.
Illustration
📝 Retrieve last stringified result:
PSJ.Parse|'{"a":1}'|$$DOC
PSJ.ToString|$$DOC|$$STR_OUTPUT // Store direct output
PSJ.GetLastResultW|$$LAST_W_RES // Retrieve the same result via this command
Result: $$STR_OUTPUT and $$LAST_W_RES will both contain the string '{"a":1}'.
Syntax
PSJ.GetLastResultW[|$$RES]
Parameter Explanation
P1 - $$RES - (Variable, String, Optional)
The variable where the last WSTRING result, converted to a UTF-8 STRING, will be stored. If omitted, the result is returned but not stored.
Technical Background
This command calls the W_JSON_GetLastWResult() function in the JSW library, which retrieves the value of the thread-local global gLastJSONWResult_W. The `CMD_1041` wrapper then calls `HTP_WideToUtf8` to convert the retrieved WSTRING into a standard STRING before returning it or storing it in the optional $$RES variable.
Examples
'***********************************
' Sample: Retrieve last result explicitly
PSJ.Parse|'["Apple", "Banana"]'|$$DOC
PSJ.ToString|$$DOC ' This populates the internal last result
PSJ.GetLastResultW|$$LAST_WSTR
PRT.Last W Result: $$LAST_WSTR ' Output: ["Apple","Banana"]
PSJ.Free|$$DOC
MBX.Ready
'***********************************
Remarks
- This retrieves the last WSTRING result, which is useful if the command that generated it didn't store it directly in an output variable or if clipboard output was disabled.
- The underlying storage is thread-local.
- The result is converted to a standard UTF-8 STRING for SSPR usage.
Limitations
- The value returned depends entirely on the last command that called the internal W_JSON_HandleResultOutput function.
See also: