一切顺利。告诉我如何解析字符串中的值is_error_send
(0 或 1):
{"count":1,
"code":0,
"data":[
{
"id":01010101,
"phone":"79111111111",
"date":"2000-01-1 01:01:11",
"msg":"test",
"id_device":1111,
"send_to_phone":"2000-01-1 01:01:1",
"is_send_to_phone":1,
"is_send":1,
"send":"2000-01-1 01:01:1",
"is_delivered":1,
"delivered":"2000-01-1 01:01:11",
"is_cancel":0,
"cancel":null,
"is_error":0,
"is_error_send":0,
"error_date":null,
"is_out":0,
"type":2,
"my_id":{}
}
]
}
使用responseText.replace(/[^\\d]/g, '').slice(0, 1)
,在这种情况下这个表达式采用第一个数字,但我有一个更复杂的问题......
这是一个示例实现,不幸的是它不起作用:
var xap = new XMLHttpRequest();
xap.open('GET', 'https://site.ru/api/out.php?token=1111&device=0101&start_id=0101&end_id=0101', true);
xap.send();
xap.onreadystatechange = function(){
if(xap.readyState == 4){
if(xap.status == 200){
console.log('result', responseText.data[0].is_error_send);
}
}
}
我建议您使用更现代的方法发送数据,例如fetch
fetch 会向指定地址发出 GET 请求,当返回响应时,第一个 .then() 将对其进行处理并将响应(这是文本)转换为对象格式(JSON)。
接下来,调用将传递到第二个 .then(),您可以在其中对接收到的对象执行必要的操作。
在上面的例子中,将值输出到控制台