I'm getting a json collection, which I want to parse. The data looks:
{
"_id" : ObjectId("589ecc1b463ede8cf7be3d17"),
"Q" : "Q1 ?",
"Rates" : [
"Q1-R1",
"Q1-R2",
"Q1-R3",
"Q1-R4"
]
}
{
"_id" : ObjectId("589ecc1b463ede8cf7be3d18"),
"Q" : "Q2 ?",
"Rates" : [
"Q2-R1",
"Q2-R2",
"Q2-R3",
"Q2-R4"
]
}
{
"_id" : ObjectId("589ecc1b463ede8cf7be3d19"),
"Q" : "Q3 ?",
"Rates" : [
"Q3-R1",
"Q3-R2",
"Q3-R3",
"Q3-R4"
]
}
I'm trying to parse with:
$.get("/getQesAns", function(data, status){
var obj = JSON.parse(data);
});
But I'm getting error:
Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
- What is wrong with the object ?
- How can I go over the elements (there is array of docs and each doc has inner array)
ObjectId("X")is not valid. You need to fix the generation code, then your JSON will automatically be parsed for you by jQuery