Reputation: 463
I am getting the following json as a response and I would like to convert it into an object.
WebSQLRows {
"_array": Array [
Object {
"bmi": 24.7,
"id": 1,
"imperialgoalweight": 154.3,
"imperialheight": 70.9,
"imperialweight": 176.4,
"metricgoalweight": 70,
"metricheight": 180,
"metricweight": 80,
"standard": "Metric",
},
Object {
"bmi": 24.7,
"id": 2,
"imperialgoalweight": 154.3,
"imperialheight": 70.9,
"imperialweight": 176.4,
"metricgoalweight": 70,
"metricheight": 180,
"metricweight": 80,
"standard": "Metric",
},
Object {
"bmi": 26.2,
"id": 3,
"imperialgoalweight": 154.3,
"imperialheight": 70.9,
"imperialweight": 187.4,
"metricgoalweight": 70,
"metricheight": 180,
"metricweight": 85,
"standard": "Metric",
},
],
"length": 3,
}
I tried using JSON.parse()
and no luck.
Any ideas as to how this can be done?
Upvotes: 0
Views: 268
Reputation: 8886
The text that you have given is probably what you are getting from console.In such a case,just remove the trailing commas.
Otherwise the text needs to be modified by removing the trailing commas as well as the data types(blue colored words)
The following is the valid JSON :
{
"_array": [
{
"bmi": 24.7,
"id": 1,
"imperialgoalweight": 154.3,
"imperialheight": 70.9,
"imperialweight": 176.4,
"metricgoalweight": 70,
"metricheight": 180,
"metricweight": 80,
"standard": "Metric"
},
{
"bmi": 24.7,
"id": 2,
"imperialgoalweight": 154.3,
"imperialheight": 70.9,
"imperialweight": 176.4,
"metricgoalweight": 70,
"metricheight": 180,
"metricweight": 80,
"standard": "Metric"
},
{
"bmi": 26.2,
"id": 3,
"imperialgoalweight": 154.3,
"imperialheight": 70.9,
"imperialweight": 187.4,
"metricgoalweight": 70,
"metricheight": 180,
"metricweight": 85,
"standard": "Metric"
}
],
"length": 3
}
Upvotes: 1