语法错误:JSON.parse:数据意外结束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19367123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 19:53:53  来源:igfitidea点击:

SyntaxError: JSON.parse: unexpected end of data

javascriptjsonrest

提问by Henrik P

I keep getting this SyntaxError when reading json parameters from a rest api in javascript.

从javascript中的rest api读取json参数时,我不断收到此SyntaxError。

Any clue what it might be?

任何线索可能是什么?

I appreciate any help

我感谢任何帮助

code:

代码:

     parseJSONResponse : function(inResult) {
     var jsonDoc = JSON.parse(inResult);

    this.fmeForm =  document.forms['fmeForm'];

    ar parameters = jsonDoc.serviceResponse.parameters.parameter;
    for( i = 0; i < parameters.length; i++) {

        if(parameters[i].type === "LOOKUP_CHOICE") {
            this.createComboBox(parameters);
        }
        if(parameters[i].type === "LISTBOX_ENCODED") {
            this.createCheckboxGroup(parameters);
        }
    }
},

And the json from a rest look like this:

其余的 json 如下所示:

      "serviceResponse": {
      "parameters": {"parameter": [
  {
     "optionsType": "MULTICHOICE_CONFIG",
     "type": "LISTBOX_ENCODED",
     "options": {"option": [
        {"value": "NOR"},
        {"value": "NOR_roads"}
     ]}
  },
  {
     "optionsType": "SINGLECHOICE_CONFIG",
     "type": "LOOKUP_CHOICE",
     "options": {"option": [
        {
           "displayAlias": "WGS84, Lat-Long; Degrees [LL84]",
           "value": "EPSG:4326"
        }
     ]}
  },
  {
     "name": "GEOM",
     "description": "",
     "defaultValue": "<lt>?xml<space>version=<quote>1.0<quote><space>encoding=     <quote>US_ASCII<quote><space>standalone=<quote>no<quote><space>?<gt><lt>geometry<gt>  <lt>polygon<gt><lt>line<gt><lt>coord<space>x=<quote>-124<quote><space>y=<quote>48<quote><solidus><gt><lt>coord<space>x=<quote>-124<quote><space>y=<quote>49.399999999999999<quote><solidus><gt><lt><solidus>line<gt><lt><solidus>polygon<gt><lt><solidus>geometry<gt>",
     "optionsType": "SINGLECHOICE_CONFIG",
     "type": "GEOMETRY",
     "options": {"option": {"value": "GEOM"}}
  },

Thanx!

谢谢!

回答by Labib Ismaiel

as everyone is stating, this is absolutely not a valid JSON, whatever the case, try validating your JSON in http://jsonlint.com/, this will show you exactly where your problem might be

正如每个人所说,这绝对不是有效的 JSON,无论如何,请尝试在http://jsonlint.com/ 中验证您的 JSON ,这将准确显示您的问题可能出在哪里

回答by azBrian

That is either a excerpt from the JSON response or a very broken result. One problem is that the comma at the end makes it invalid JSON...

那要么是 JSON 响应的摘录,要么是非常糟糕的结果。一个问题是末尾的逗号使它成为无效的 JSON...