JSON+Node.js - Unexpected token o

前端 未结 2 844
悲哀的现实
悲哀的现实 2020-12-15 17:28

I just started working with node.js and json objects in my college course. One of our assignments this week was to create a few json objects and extract parts of the object

相关标签:
2条回答
  • 2020-12-15 18:05

    the solution is to use JSON.stringify as follows

    var target=JSON.parse(JSON.stringify(source));
    
    0 讨论(0)
  • 2020-12-15 18:07

    Your colleges variable is already a valid JavaScript Object. You do not have to use JSON.parse on it.

    JSON.parse expects a String as first argument, but you provide an Object. Thus it is coerced to a String looking like the one you see in the Error message.

    For the rest of your code, you might want to take a look at Express or Zappa to be able to write the code a bit more compact ;)

    0 讨论(0)
提交回复
热议问题