My responseJson is structured as follows:
const responseJson = [
{
device_id: "arena-FnVq4HTwtBg6JqqBxWBB7W",
timestamp: "2020-02-10T20:52:00.000Z",
data: "{"type": "DATA", "unitID": "arena-FnVq4HTwtBg6JqqBxWBB7W",
"version": "1.0.0",
"voltage": [130.0222, 129.9743, 129.9567, 129.9853, 130.0043, 130.0257, 130.067,
130.1005, 130.0698, 130.1056],
"frequency": [60.0005, 60.0001, 59.9984, 59.9999, 59.9992, 59.9971, 59.9977,
59.9979, 59.999, 59.9985],
"timestamp": 1581367920000,
"phaseAngle": [2.5766, 2.5769, 2.5768, 2.5761, 2.5754, 2.574, 2.5718, 2.5706,
2.569, 2.5677]}"
}
]
In my data
, the structure looks like a string rather than an object. How can I parse this data correctly?
const responseJson = [
{
device_id: "arena-FnVq4HTwtBg6JqqBxWBB7W",
timestamp: "2020-02-10T20:52:00.000Z",
data: {"type": "DATA", "unitID": "arena-FnVq4HTwtBg6JqqBxWBB7W",
"version": "1.0.0",
"voltage": [130.0222, 129.9743, 129.9567, 129.9853, 130.0043, 130.0257, 130.067,
130.1005, 130.0698, 130.1056],
"frequency": [60.0005, 60.0001, 59.9984, 59.9999, 59.9992, 59.9971, 59.9977,
59.9979, 59.999, 59.9985],
"timestamp": 1581367920000,
"phaseAngle": [2.5766, 2.5769, 2.5768, 2.5761, 2.5754, 2.574, 2.5718, 2.5706,
2.569, 2.5677]}
}
]
I have attempted to use JSON.parse but without success.
Here is what I receive when I log the following:
console.log(responseJson.data)
throws undefined
console.log(JSON.parse(responseJson.data))
throws C:\Users\aravi\Desktop\React\Reactnative\BrixonApplication_App\node_modules\react-native\Libraries\Core\ExceptionsManager.js:94 SyntaxError: Unexpected token u in JSON at position 0