Uncaught SyntaxError: Unexpected token p in JSON at position 36

Gerry

I´m populating webpage with sharepoint so I do a json to get data with ajax like these:

function completeFleet(data, target, eng) {
var items = data.d.results;
console.log(items);
var prefix = "<div class='row'>";
var sufix = "</div>";
var menu = "<div class='col-md-4'>";
var cat = "";
var spec = "";
var counter = 0;
var obj = null;
for (item in items) {
    spec = "";
    if (counter == 1) {

        menu += "</div><div class='col-md-4'>";
        counter = 0;
    }
    if (eng) {
        obj = JSON.parse(items[item].Specifications);
        for (var key in obj) {
            spec += "<div class='row'><div class='col-md-12 ftBottomSeparator'><span class=' t10'>" + key + "</span>&nbsp;<span class='t06' style='float:right;'>" + obj[key] + "</span></div></div>";
        }
        menu += "<div class='row ftContainerOut'><div class='col-md-12 ftContainer'><div class='row ftHeader'><div class='col-xs-9 t09'>" + items[item].Title + "</div><div class='col-xs-3 text-right'></div></div><div class='row'><div class='col-md-6' style='padding-top:10px'><img src='" + items[item].Imagen.Url + "' class='img-responsive img-center' style='border:0px solid blue; max-width:150px;max-height:120px;' /></div><div class='col-md-6'>" + spec + "</div></div></div></div>";
    } else {
        obj = JSON.parse(items[item].Especificaciones);
        for (var key in obj) {
            spec += "<div class='row'><div class='col-md-12 ftBottomSeparator'><span class=' t10'>" + key + "</span>&nbsp;<span class='t06'  style='float:right;'>" + obj[key] + "</span></div></div>";
        }

        menu += "<div class='row ftContainerOut'><div class='col-md-12 ftContainer'><div class='row ftHeader'><div class='col-xs-9 t09'>" + items[item].Title + "</div><div class='col-xs-3 text-right'></div></div><div class='row'><div class='col-md-6' style='padding-top:10px'><img src='" + items[item].Imagen.Url + "' class='img-responsive img-center' style='border:0px solid blue; max-width:150px;max-height:120px;' /></div><div class='col-md-6'>" + spec + "</div></div></div></div>";
    }
    counter++;
}
$(target).html("<div class='panel-body'><div class='container-fluid'>" + prefix + menu + sufix + "</div></div>");

}

I have 5 objects different, but one of these don´t show data, my webpage is in english and spanish, in english it charge all data, but in spanish one of these doesn´t works and I get error at position 36, and position 36 is the item don´t show. Any idea what is wrong here? Regards

Error image

These one works Works

and this no works

noworks

---------Update------------

If I comment this line:

 //obj = JSON.parse(items[item].Especificaciones);

and put

 if(items[item].Especificaciones){
 JSON.parse(items[item].Especificaciones);
   }

it now runs with image, but now I don´t have my "Especificaciones" lists

Now when I use

var stringifyObj = JSON.stringify(items[item].Especificaciones); 
var obj = JSON.parse(stringifyObj);

I get something like these:

Keyword

Kawsar Hamid

make sure value is not null for the corresponding key inside JSON.parse. For example-

JSON.parse(items[item].Specifications)

make sure items have value in item index and items[item] has the property Specifications.

you can check if items[item].Specifications is not null before JSON.parse.

if(items[item].Specifications){
  JSON.parse(items[item].Specifications)
}

Update

JSON.parse() is used to convert a string containing JSON notation into a Javascript object. To be valid JSON, strings must be in double quotes.

Try stringify the object and then parse again.

var stringifyObj = JSON.stringify(items[item].Especificaciones); 
var obj = JSON.parse(stringifyObj);

The reason for the error is that JSON.parse() expects a String value and items[item].Especificaciones is an Array

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Uncaught SyntaxError: Unexpected token u in JSON at position 0

React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

Uncaught SyntaxError: Unexpected token with JSON.parse

Uncaught SyntaxError: Unexpected token < in JSON at position 0 : at JSON.parse (<anonymous>) at Object.<anonymous>

SyntaxError: Unexpected token \ in JSON at position

Uncaught SyntaxError: Unexpected token U in JSON at position 0 at JSON.parse (<anonymous>) at Response.Body.json

JSON object issue: Uncaught SyntaxError: Unexpected token

Uncaught SyntaxError: Unexpected token o in JSON at position 1 error

"Uncaught SyntaxError: Unexpected token H in JSON"

SyntaxError: Unexpected token } in JSON at position

Jinja Flask issue: Uncaught SyntaxError: Unexpected token { in JSON at position 1 at JSON.parse

how to fix "Uncaught SyntaxError: Unexpected token _ in JSON at position . . . "

how to fix Uncaught SyntaxError: Unexpected token o in JSON at position 1

Uncaught SyntaxError: Unexpected token , in JSON at position 10

Uncaught SyntaxError: Unexpected token c in JSON at position 13

javascript json uncaught syntaxerror unexpected token illegal

Uncaught SyntaxError: Unexpected token - JSON character encoding

"Uncaught SyntaxError: Unexpected token" with JSON parse in backbone

JSON Parse: Uncaught SyntaxError: Unexpected token e

Selectize Uncaught SyntaxError: Unexpected token # in JSON at position 0

Uncaught SyntaxError: Unexpected token a in JSON at position 0 at JSON.parse (<anonymous>)

Uncaught SyntaxError: Unexpected token d in JSON at position 0 at JSON.parse (<anonymous>)

Uncaught SyntaxError: Unexpected token < in JSON at position 0 from Codeigniter response

Uncaught SyntaxError: Unexpected token T in JSON at position 0 at JSON.parse (Asp.net MVC)

Angular SyntaxError: Unexpected token P in JSON at position 0

Uncaught Promise Rejection SyntaxError: Unexpected token u in JSON at position 0

Uncaught SyntaxError: Unexpected token a in JSON at position 2

Uncaught (in promise) SyntaxError: Unexpected token r in JSON at position 0

Facing an Uncaught SyntaxError: Unexpected token o in JSON at position 1