Use this method to create a JavaScript object from a JSON string. The ca_pam_convertJSONToJSObject method supports quotation marks notation. Quotation marks notation is an alternate way to access any property from a JavaScript object when the property name is not a valid JavaScript identifier. For example, to access the id property from the book object, quotation marks notation syntax is book[“id”].
Defines the JSON string to convert to a JavaScript object.
Returns the JavaScript object.
The example shows a JSON string:
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
The following sample script accesses the id field value:
var parsedJSON = ca_pam_convertJSONToJSObject(jsonString); var menuObj = parsedJSON.menu.; var idValue = menuObj.id.;
The following sample script accesses the onclick element in the second element of the menuitem array:
var parsedJSON = ca_pam_convertJSONToJSObject(jsonString); var menuObj = parsedJSON.menu; var popUpObj = menuObj .popup; var menuItemArray = popUpObj .menuitem.; var secondElementOfMenuItemArray = menuItemArray[1]; var onclickElement = secondElementOfMenuItemArray.onclick;
You can also find this function in the out-of-the-box content in CA Process Automation.
|
Copyright © 2013 CA.
All rights reserved.
|
|