Quantcast
Channel: VMware Communities : All Content - vRealize Automation Tools
Viewing all articles
Browse latest Browse all 9859

JSON.parse a tag with "-" in it

$
0
0

I am trying to do a request but one of the tags has a "-" in it.  How to I retrieve that attribute

Code is below:

var restAction = "/login/";

var postData = "username=test&password=xxxx";

var request = restHost.createRequest("POST",restAction,postData);

request.contentType = "application/x-www-form-urlencoded";

 

var response = request.execute();

System.log(response.statusCode);

if (response.statusCode < 202) {

  //this is ok

  JSONdata = response.contentAsString;

  System.log(JSONdata);

} else {

  throw("Return code: "+response.statusCode + " Response body: "+response.contentAsString);

}

 

 

var jsonData = JSON.parse(JSONdata);

System.log(jsonData.x-token);

 

Response:

[2016-10-19 10:27:08.650] [I] 200

[2016-10-19 10:27:08.650] [I] {

  "Set-Cookie": "token123456"; expires=Wed, 19 Oct 2016 22:22:20 GMT; Path=/",

  "result": "authenticated",

  "username": "o361404",

  "x-token": "token123456"

}

2016-10-19 10:36:32.756] [I] ReferenceError: "token" is not defined. (Workflow:GNOME / Scriptable task (item1)#16)

 

How do I parse the "x-token" attribute


Viewing all articles
Browse latest Browse all 9859

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>