Javascript 从moderatecontent结果访问对象值
我正在使用Javascript 从moderatecontent结果访问对象值,javascript,html,json,ajax,xmlhttprequest,Javascript,Html,Json,Ajax,Xmlhttprequest,我正在使用mediateContentapi检测图像、视频或文件是否包含特定的不适当内容。但是,在我选择从结果返回的对象中的键中专门选择一个值之前,所有这些操作当前都有效 我使用的代码如下: var ajax\u url=”https://api.moderatecontent.com/moderate/"; var image\u url=“sample\u face\u 2.jpg”; var xhttp=newXMLHttpRequest(); xhttp.onreadystatechan
mediateContent
api检测图像、视频或文件是否包含特定的不适当内容。但是,在我选择从结果返回的对象中的键中专门选择一个值之前,所有这些操作当前都有效
我使用的代码如下:
var ajax\u url=”https://api.moderatecontent.com/moderate/";
var image\u url=“sample\u face\u 2.jpg”;
var xhttp=newXMLHttpRequest();
xhttp.onreadystatechange=函数(){
如果(xhttp.readyState==4&&xhttp.status==200){
console.log(xhttp.responseText)
}
};
xhttp.open(“GET”,ajax\u url+”?key=1234567890&url=“+image\u url,true);
xhttp.send();
这将作为以下内容登录到控制台:
{
"url_classified": "sample_face_2.jpg",
"rating_index": 1,
"rating_letter": "e",
"predictions": {
"teen": 0.11751182222118,
"everyone": 99.823732266668,
"adult": 0.05875591111059
},
"rating_label": "everyone",
"error_code": 0,
"frame": 1
}
但是,我如何从上面生成的对象中具体获得“成人”评级?
我曾尝试使用this.maintal
或console.log(xhttp.responseText.predictions)
但这些结果在打印到控制台时会导致错误或“未定义”
我还检查了文档,但没有显示如何从它返回的对象中检索这些特定值
如果有人能帮忙,我真的很感激 查看执行
console.log(JSON.parse(xhttp.responseText.predictions))
时得到的结果?谢谢,这很有效