此特定应用程序以 application/json;charset=UTF-8
格式返回 content-type
header
我不确定这是否可以更改并减少为仅“application/json”,或者如果我在其他地方重复使用此代码?
我的代码是
response.headers['Content-Type'].match(/text\/application//json/i)
如何最好地检查内容类型 application/json???
最佳答案
你可以使用RegExp
/application\/json/
var response = {"Content-Type":"application/json;charset=UTF-8"};
console.log(response["Content-Type"].match(/application\/json/)[0]);
关于javascript - 用于检查内容类型 application/json 等的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38033634/