I Keep Getting "Uncaught Syntaxerror: Unexpected Token O"

SyntaxError: Unexpected token o in JSON at position 1

The JSON you posted looks fine, however in your code, it is most likely not a JSON string anymore, but already a JavaScript object. This means, no more parsing is necessary.

You can test this yourself, e.g. in Chrome's console:

new Object().toString()
// "[object Object]"

JSON.parse(new Object())
// Uncaught SyntaxError: Unexpected token o in JSON at position 1

JSON.parse("[object Object]")
// Uncaught SyntaxError: Unexpected token o in JSON at position 1

JSON.parse() converts the input into a string. The toString() method of JavaScript objects by default returns [object Object], resulting in the observed behavior.

Try the following instead:

var newData = userData.data.userList;

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

No need to use parse again , its already json

$.ajax({
url: "/url/url.ajax?length=100000&startDate=2018-07-01",
method: "get",
dataType: "json",
success: function (jdata) {
var jsonData=jdata.data;
}
});

$.ajax({

url: "https://jsonplaceholder.typicode.com/posts",

method: "get",

dataType: "json",

success: function (jdata) {

var jsonData=jdata

console.log(jsonData)

}

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

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

first line of showNotes function (line 117 on your screen shot), let Notes = … "Notes" should have a lower "n"

Uncaught SyntaxError: Unexpected token :

I have just solved the problem. There was something causing problems with a standard Request call, so this is the code I used instead:

vote.each(function(element){                
element.addEvent('submit', function(e){
e.stop();
new Request.JSON({
url : e.target.action,
onRequest : function(){
spinner.show();
},
onComplete : function(){
spinner.hide();
},
onSuccess : function(resp){
var j = resp;
if (!j) return false;
var restaurant = element.getParent('.restaurant');
restaurant.getElements('.votes')[0].set('html', j.votes + " vote(s)");
$$('#restaurants .restaurant').pop().set('html', "Total Votes: " + j.totalvotes);
buildRestaurantGraphs();
}
}).send(this);
});
});

If anyone knows why the standard Request object was giving me problems I would love to know.

How to fix Unexpected token o in JSON at position 1 using JavaScript?

add json()
let data = res.json();

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

You are parsing the data that is already parsed,

try using "data" directly

$("#search").change(function () {
$("html, body").animate({ scrollTop: $(".calendar").offset().top }, 1500);
var selectedEvent = $("#search").val();

$.getJSON('events.json', function (data) {

render(selectedEvent, data);
});
});


Related Topics



Leave a reply



Submit