0
Why do i get unexpected end of JSON input at JSON.parse <anonymous> error? [unsolved]
Here is the code that produces the error ,also i am not sure why content length is logged out as 1 ,maybe I don't understand how this method really works ,so pls help me clear my doubts,thanks in advance const content=" " req.on('data',(chunk)=>{ content+=chunk; }) req.on("end",()=>{ console.log(content.length); console.log(content,JSON.parse(conten t)); });
6 Antworten
+ 4
You have extra two brackets at the end i think. And a constant can't be changed so use let instead of const.
+ 2
Try console log without json parse and see what you try to convert and see if there is allready a bug there
+ 1
maf there is no extra brackets ,also let ,const and var nothing works
+ 1
Dragonxiv when I simply remove all statements and just do console.log(content) then I get {"message":"hii"} which is the message I am sending but when I do ,
console.log(content.length)
console.log(content,JSON.parse(content));
Here the content is just " " whose length is one and it can't be parsed ,
+ 1
Dragonxiv yes but json.parse on content doesn't works strangely as from some stackoverflow question and my own assumption content is just " " instead of message:hi when parsed ,I am not sure but if this isn't reason I am not able to understand why I get the above error
0
And you put the console.log inside the req.on('end',()=> { here ?})