简体   繁体   English

读取Javascript中的JSON响应

[英]Reading a JSON response in Javascript

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. 我正在向一个超简单的python函数发出ajax发布请求,该函数接受一个学生的名字并吐出一个与之对应的URL。 Currently, the Python function passes this back in json and looks like so when console.log(JSON.stringify(response)) is called: 当前,Python函数将此内容传回json,并在调用console.log(JSON.stringify(response))时看起来像这样:

{"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? 我想知道如何获取大量信息并对其进行过滤,以便仅获得https://prepacademy.jackjohnson.com部分?

response is a JavaScript Object of which you can access the properties using either Dot-notation or bracket-notation, like so: response是一个JavaScript对象,您可以使用点符号或方括号符号访问其JavaScript属性,如下所示:

 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM