Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何删除json中的最后一个1?_Javascript_Php_Ajax - Fatal编程技术网

Javascript 如何删除json中的最后一个1?

Javascript 如何删除json中的最后一个1?,javascript,php,ajax,Javascript,Php,Ajax,我正在使用一个api,我得到了这个响应 { "categories": [ [ "Related Queries", [ { "value": "tower", "formInput": "tower" }, { "value": "erection", &q

我正在使用一个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 &amp; 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
我的获取API数据的PHP文件如下

function getData(){
var queryData = { 'query': 'jio'};
  $.ajax({
    type: "POST",
     url: 'api.php',
     data: queryData,
     dataType: 'html',
     success: function(response) {
       console.log(response);
}
            
      });
<?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:JSON中位于8986位置的意外数字


如何快速而肮脏地解决此错误,我将在PHP代码中执行以下操作

$rest = substr($rest, 0, -1);

我不会说这是“肮脏的”。这不是一项艰苦的工作。这就是解决办法。。。。提供一个
trim()
也是为了以防万一而应用的。感谢Marcho Bishchoff,这解决了我的问题。@GetSet这取决于,如果“1”直接来自JSON响应,那么它就是解决方案,如果它来自PHP代码,那么就称之为quick and dirty。我会说它不是来自JSON,因为它将是无效的JSON。这是否回答了您的问题?