Hi,
I am using an API endpoint to serve as a flow hook, to receive back status.
The only problem is the request.content is coming back as query string and I need it as a JSON string.
How can I convert the variable request.content and convert it into JSON?
For an example, I want to convert the following, into what's below:
key1=value1&key2=value2&key3=value3
{ "key1": "value1", "key2": "value2", "key3": "value3" }
A simple Javascript function should do the trick. See an example here: http://www.developerdrive.com/2013/08/turning-the-querystring-into-a-json-object-using-javascript/
Solved this using the JavaScript below:
var jsonOutput = ''; var queryStringPairs = context.getVariable("request.content").split("&"); queryStringPairs.forEach(function(nameValuePair) { var nameAndValue = nameValuePair.split('='); xmlOutput += '"' + nameAndValue[0] + '"' + ':' + '"' + nameAndValue[1] + '"' + ','; }); jsonOutput = '{' + jsonOutput.substr(0, jsonOutput.length -1) + '}'; context.setVariable('request.content', jsonOutput);
just replace xmlOutput with jsonOutput and it will work.
Nowadays, every off-page SEO professional performs this profile creation activity in order to get long term backlinks and several inbound links that SERPs, including Google, appreciate. If you also want to rank your website high on Google, then don’t waste your time, start building your links on profile creation sites and increase your online visibility.
By Solid Waste Management Authorization
This allows you to then access the values of the query string using the array accessor syntax.
//domain.com/index.html?key=value var value = querystring_array['key']; <br> Still a little clumsy isn’t it? Wouldn’t it be great to be able to just retrieve the value from a normal JavaScript/JSON object?
//domain.com/index.html?key=value var value = querystring.key;
User | Count |
---|---|
5 | |
2 | |
2 | |
1 | |
1 |