frankthemaster
9 years agoNew Contributor
Solved
Need help pasrsing api response
Hi all, I'm new to testcomplete and I'm assigned to write test scripts using jscript for some API testing. For one of the test, I need to parse JSON response and retrive a key of some sort and sa...
- 9 years ago
Basically the JSON.parse is a built in Jscript function that goes through the response text formatted as JSON. and creates an array of all the objects in it with their properties. Your response only has one object with several properties one of the properties being 'key'.
So after it has been parsed you have an array called json, with one object at position 0, or json[0], the porpety is accessed by it's name 'key'.
More reading that might help clear it up more as well:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
http://www.w3schools.com/js/js_objects.asp
http://www.w3schools.com/js/js_json.asp
http://www.w3schools.com/js/js_arrays.asp