javascript - 如何删除json中的最后一个?
问题描述
我正在使用一个 api,因此我得到了这个响应
{
"categories": [
[
"Related Queries",
[
{
"value": "tower",
"formInput": "tower"
},
{
"value": "erection",
"formInput": "erection"
},
{
"value": "police protection",
"formInput": "police%20protection"
},
{
"value": "to provide police protection",
"formInput": "to%20provide%20police%20protection"
},
{
"value": "phone tower",
"formInput": "phone%20tower"
}
]
],
[
"Document Types",
[
{
"value": "All",
"formInput": "jio",
"selected": true
},
{
"value": "Laws",
"formInput": "jio+doctypes:laws"
},
{
"value": "Judgments",
"formInput": "jio+doctypes:judgments"
},
{
"value": "Highcourts",
"formInput": "jio+doctypes:highcourts"
},
{
"value": "HC & SC",
"formInput": "jio+doctypes:supremecourt,scorders,highcourts"
}
]
],
[
"Courts",
[
{
"value": "chennai",
"formInput": "jio+doctypes:chennai",
"selected": false
},
{
"value": "kerala",
"formInput": "jio+doctypes:kerala",
"selected": false
},
{
"value": "cat_delhi",
"formInput": "jio+doctypes:cat_delhi",
"selected": false
},
{
"value": "bombay",
"formInput": "jio+doctypes:bombay",
"selected": false
},
{
"value": "delhi",
"formInput": "jio+doctypes:delhi",
"selected": false
},
{
"value": "supremecourt",
"formInput": "jio+doctypes:supremecourt",
"selected": false
},
{
"value": "patna",
"formInput": "jio+doctypes:patna",
"selected": false
},
{
"value": "patna_orders",
"formInput": "jio+doctypes:patna_orders",
"selected": false
},
{
"value": "jodhpur",
"formInput": "jio+doctypes:jodhpur",
"selected": false
},
{
"value": "madhyapradesh",
"formInput": "jio+doctypes:madhyapradesh",
"selected": false
}
]
],
[
"Authors",
[
{
"value": "K Venkataswami",
"formInput": "jio+author:K Venkataswami"
},
{
"value": "S Sanyal",
"formInput": "jio+author:S Sanyal"
},
{
"value": "S.C.Sharma",
"formInput": "jio+author:S.C.Sharma"
}
]
],
[
"Years",
[
{
"value": 2015,
"formInput": "jio+fromdate:1-1-2015+todate:31-12-2015"
},
{
"value": 2016,
"formInput": "jio+fromdate:1-1-2016+todate:31-12-2016"
},
{
"value": 2014,
"formInput": "jio+fromdate:1-1-2014+todate:31-12-2014"
},
{
"value": 2019,
"formInput": "jio+fromdate:1-1-2019+todate:31-12-2019"
},
{
"value": 2011,
"formInput": "jio+fromdate:1-1-2011+todate:31-12-2011"
}
]
]
],
"docs": [
{
"title": "M/S. Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 22 January, 2016",
"covertitles": [
],
"numcites": 2,
"numcitedby": 0,
"url": "http://judis.nic.in/Judis_Chennai/list_new2.asp?FileName=259280",
"headline": "Madras High Court \n M/S. Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 22 January, 2016 \n\n \nIN THE HIGH ... Reliance <b>Jio</b> Infocomm Limited\nhaving its circle office at \nA1 Tower, 8th Floor,\n89-90, Dr.Radhakrishnan Salai,\nMylapore, \nChennai",
"docsize": 3785,
"tid": 90453177,
"covertids": [
],
"doctype": 24,
"publishdate": "2016-01-22",
"firstname": null,
"secondname": null,
"lastname": null,
"fragment": true,
"docsource": "Madras High Court",
"covers": [
]
},
{
"title": "M/S.Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 29 January, 2016",
"covertitles": [
],
"numcites": 1,
"numcitedby": 0,
"url": "http://judis.nic.in/Judis_Chennai/list_new2.asp?FileName=260428",
"headline": "Madras High Court \n M/S.Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 29 January, 2016 \n\n \nIN THE HIGH ... Reliance <b>Jio</b> Infocomm Limited,\nHaving its Circle Office at\nA1 Tower, 8th Floor,\n89-90, Dr.Radhakrishnan Salai,\nMalpore Chennai",
"docsize": 3458,
"tid": 52215865,
"covertids": [
],
"doctype": 24,
"publishdate": "2016-01-29",
"firstname": null,
"secondname": null,
"lastname": null,
"fragment": true,
"docsource": "Madras High Court",
"covers": [
]
},
{
"title": "M/S.Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 26 August, 2015",
"covertitles": [
],
"numcites": 1,
"numcitedby": 0,
"url": "http://judis.nic.in/Judis_Chennai/list_new2.asp?FileName=239394",
"headline": "Madras High Court \n M/S.Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 26 August, 2015 \n\n \nIN THE HIGH ... Reliance <b>Jio</b> Infocomm Limited\t\t\t\t\t\nHaving its Circle Office at\nA1 Tower, 8th Floor,\n89-90, Dr.Radhakrishnan Salai,\nMylapore, Chennai",
"docsize": 3599,
"tid": 121257329,
"covertids": [
],
"doctype": 24,
"publishdate": "2015-08-26",
"firstname": null,
"secondname": null,
"lastname": null,
"fragment": true,
"docsource": "Madras High Court",
"covers": [
]
},
{
"title": "M/S Reliance <b>Jio</b> Infocomm Ltd. vs The State Of Bihar & Ors on 10 August, 2015",
"covertitles": [
],
"numcites": 2,
"numcitedby": 0,
"url": null,
"headline": "Patna High Court - Orders \n M/S Reliance <b>Jio</b> Infocomm Ltd. vs The State Of Bihar & Ors on 10 August ... Case No.7591 of 2015\n======================================================\n1. M/s Reliance <b>JIO</b> Infocomm Ltd., a companywithin the meaning of the\n Companies",
"docsize": 7026,
"tid": 22796076,
"covertids": [
],
"doctype": 45,
"publishdate": "2015-08-10",
"firstname": null,
"secondname": null,
"lastname": null,
"fragment": true,
"docsource": "Patna High Court - Orders",
"covers": [
]
},
{
"title": "M/S.Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 26 August, 2015",
"covertitles": [
],
"numcites": 1,
"numcitedby": 0,
"url": "http://judis.nic.in/Judis_Chennai/list_new2.asp?FileName=239260",
"headline": "Madras High Court \n M/S.Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 26 August, 2015 \n\n \nIN THE HIGH ... Reliance <b>Jio</b> Infocomm Limited\t\t\t\t\t\nHaving its Circle Office at\nA1 Tower, 8th Floor,\n89-90, Dr.Radhakrishnan Salai,\nMylapore, Chennai",
"docsize": 3547,
"tid": 17100782,
"covertids": [
],
"doctype": 24,
"publishdate": "2015-08-26",
"firstname": null,
"secondname": null,
"lastname": null,
"fragment": true,
"docsource": "Madras High Court",
"covers": [
]
},
{
"title": "M/S.Reliance <b>Jio</b> Inforcomm ... vs The Assistant Engineer on 26 August, 2015",
"covertitles": [
],
"numcites": 1,
"numcitedby": 0,
"url": "http://judis.nic.in/Judis_Chennai/list_new2.asp?FileName=239488",
"headline": "Madras High Court \n M/S.Reliance <b>Jio</b> Inforcomm ... vs The Assistant Engineer on 26 August, 2015 \n\n \nIN THE HIGH COURT ... Reliance <b>Jio</b> Inforcomm Limited,\nhaving Circle Office at A1 Tower,\n8th Floor, 89-90, Dr.Radhakrishnan Salai,\nMylapore, Chennai",
"docsize": 4056,
"tid": 76372287,
"covertids": [
],
"doctype": 24,
"publishdate": "2015-08-26",
"firstname": null,
"secondname": null,
"lastname": null,
"fragment": true,
"docsource": "Madras High Court",
"covers": [
]
},
{
"title": "M/S.Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 15 April, 2015",
"covertitles": [
],
"numcites": 1,
"numcitedby": 0,
"url": "http://judis.nic.in/judis_chennai/qrydisp.aspx?filename=77566",
"headline": "Madras High Court \n M/S.Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 15 April, 2015 \n\n \n\n \n\n \n \n BEFORE THE MADURAI ... 6885 of 2015:\n\nM/s.Reliance <b>Jio</b> Infocomm Limited,\nhaving its Circle Office at A1 Tower, 8th Floor",
"docsize": 5103,
"tid": 187432957,
"covertids": [
],
"doctype": 24,
"publishdate": "2015-04-15",
"firstname": null,
"secondname": null,
"lastname": null,
"fragment": true,
"docsource": "Madras High Court",
"covers": [
]
},
{
"title": "M/S.Reliance <b>Jio</b> Infocomm ... vs The Assistant Engineer on 19 March, 2015",
"covertitles": [
],
"numcites": 1,
"numcitedby": 0,
"url": "http://judis.nic.in/judis_chennai/qrydisp.aspx?filename=77273",
"headline": "Madras High Court \n M/S.Reliance <b>Jio</b> Infocomm ... vs The Assistant Engineer on 19 March, 2015 \n\n \n\n \n\n \n \n BEFORE THE MADURAI BENCH ... 16988 of 2014\n\n\nM/s.Reliance <b>Jio</b> Infocomm Limited,\nhaving Circle office at A1 Tower, 8th Floor",
"docsize": 4761,
"tid": 76302150,
"covertids": [
],
"doctype": 24,
"publishdate": "2015-03-19",
"firstname": null,
"secondname": null,
"lastname": null,
"fragment": true,
"docsource": "Madras High Court",
"covers": [
]
},
{
"title": "M/S. Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 10 February, 2015",
"covertitles": [
],
"numcites": 1,
"numcitedby": 0,
"url": "http://judis.nic.in/judis_chennai/qrydisp.aspx?filename=212570",
"headline": "Madras High Court \n M/S. Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 10 February, 2015 \n\n \n\n \n\n \n \n IN THE HIGH ... Reliance <b>Jio</b> Infocomm Limited,\nhaving its Circle office at A1 Tower, 8th Floor,\n89-90, Dr. Radhakrishnan Salai,\nMylapore, Chennai",
"docsize": 3804,
"tid": 73976485,
"covertids": [
],
"doctype": 24,
"publishdate": "2015-02-10",
"firstname": null,
"secondname": null,
"lastname": null,
"fragment": true,
"docsource": "Madras High Court",
"covers": [
]
},
{
"title": "M/S.Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 18 February, 2015",
"covertitles": [
],
"numcites": 1,
"numcitedby": 0,
"url": "http://judis.nic.in/judis_chennai/qrydisp.aspx?filename=214508",
"headline": "Madras High Court \n M/S.Reliance <b>Jio</b> Infocomm ... vs The Inspector Of Police on 18 February, 2015 \n\n \n\n \n\n \n \n IN THE HIGH ... Reliance <b>Jio</b> Infocomm Limited,\nhaving its Circle Office at A1 Tower, 8th Floor,\n89-90, Dr.Radhakrishnan Salai,\nMylapore, Chennai",
"docsize": 3361,
"tid": 171042175,
"covertids": [
],
"doctype": 24,
"publishdate": "2015-02-18",
"firstname": null,
"secondname": null,
"lastname": null,
"fragment": true,
"docsource": "Madras High Court",
"covers": [
]
}
],
"found": "11 - 20 of 1436",
"encodedformInput": "jio"
}1
在响应结束时,我在响应中得到 1,而这个 1 给我解析 json 带来了问题。我的javascript文件如下
function getData(){
var queryData = { 'query': 'jio'};
$.ajax({
type: "POST",
url: 'api.php',
data: queryData,
dataType: 'html',
success: function(response) {
console.log(response);
}
});
我正在获取 API 数据的 PHP 文件如下
<?PHP
extract($_POST,EXTR_OVERWRITE);
$headr = array();
$headr[] = 'X-MESSAGE:' .base64_encode('dfsf');
$headr[] = 'X-EMAIL: p******@gmail.com';
$headr[] = 'Authorization:Token **************e453966e';
$url = "https://api.indiankanoon.org/search/?formInput=$query&pagenum=1";
$crl = curl_init();
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_HTTPHEADER, $headr);
curl_setopt($crl, CURLOPT_POST, true);
$rest = curl_exec($crl);
if ($rest === false)
{
// throw new Exception('Curl error: ' . curl_error($crl));
print_r('Curl error: ' . curl_error($crl));
}
curl_close($crl);
// $rest = json_encode($rest, JSON_PRETTY_PRINT);
echo json_decode($rest);
exit;
?>
我得到的错误如下
未捕获的 SyntaxError:位置 8986 处的 JSON 中的意外数字
如何解决此错误
解决方案
又快又脏,我会在 PHP 代码中执行以下操作
$rest = substr($rest, 0, -1);
推荐阅读
- reactjs - 反应更糟糕的做法:更胖的状态或 DOM 操作?
- python-3.x - 接收到的消息与通过串行连接发送的消息不同
- asp.net-core - Azure 管道缺少引用
- mysql - 使用状态在 React 中显示节点 MySQL 结果
- excel - 如何根据行值自动隐藏列,该行值基于对面工作表中的 if 函数?
- javascript - 如何迭代 XMLHttpRequest?
- android - 有没有办法从 Genymotion 虚拟机中恢复我的应用程序?
- laravel - Laravel按月分组的列集合总和
- javascript - 切换 SVG 图标的颜色
- c# - Selenium WebDriver 在重定向期间没有响应