5

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

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:

      "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!

4
  • 2
    That's not a complete JSON literal. What is the exact value of inResult, and what does it come from? Commented Oct 14, 2013 at 18:51
  • 2
    @SLaks: What's a "JSON literal"? It's either a "JSON string" or an "object literal". Commented Oct 14, 2013 at 18:52
  • Most likely there's an unclosed parentheses or quote mark in the JSON -- looks like you haven't posted the full JSON here. One thing I like to try is to paste my JSON into jsoneditoronline.org, which will format it nicely (if it's valid) and give an error message if not. Commented Oct 14, 2013 at 18:54
  • It's also possible that parseJSONResponse is not called correctly. Commented Aug 26, 2020 at 19:36

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

Comments

0

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.