I'm making an ajax post request to a super simple python function that takes a student's name and spits out a url that corresponds to it. Currently, the Python function passes this back in json and looks like so when console.log(JSON.stringify(response))
is called:
{"readyState":4,"responseText”:”\\ {\\”studentURL\\”: \\”https://prepacademy.jackjohnson.com\\”} ”,”responseJSON”: {“studentURL”:”https://prepacademy.jackjohnson.com”},”status":200,"statusText":"OK"}
I was wondering how do I take this larger chunk of information and filter it so that I would only get the https://prepacademy.jackjohnson.com
part?
response
is a JavaScript Object of which you can access the properties using either Dot-notation or bracket-notation, like so:
let response = { "readyState": 4, "responseText": "\\ {\\"studentURL\\": \\"https://prepacademy.jackjohnson.com\\"} ", "responseJSON": { "studentURL": "https://prepacademy.jackjohnson.com" }, "status": 200, "statusText": "OK" }; // dot-notation console.log(response.responseJSON.studentURL) // bracket-notation (allows for computed paths) console.log(response["responseJSON"]["studentURL"])
response.responseJSON.studentURL
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.