I am planning to have coordinates sent to the google maps API but i am unable to delete the field name from my json object in order to send the parameters through.
Object {TempPoints: "{lat: 51.478,lng: -3.192},{lat: 51.478,lng: -3.192…{lat: 51.47840998047034,lng: -3.1926937697490536}"}
how do i remove 'TempPoints:' from the object
desired output
Object {"{lat: 51.478,lng: -3.192},{lat: 51.478,lng: -3.192…{lat: 51.47840998047034,lng: -3.1926937697490536}"}
essentially i am trying to recreate something like this
flightPlanCoordinates = [{lat: 51.478,lng: -3.192},{lat: 51.478,lng: -3.192},{lat: 51.478,lng: -3.192},{lat: 51.47845554862494,lng: -3.1928923123350774},{lat: 51.47848027862647,lng: -3.1929894662780804}];
PHP Code as requested
$sql = $dbh->prepare("SELECT TempPoints FROM session WHERE CustomerID = 2 ORDER BY SessionID DESC LIMIT 1");
$sql->execute();
$row = $sql->fetch(PDO::FETCH_ASSOC);
$para = implode(" ",$row);
echo json_encode($row);
Answer
Object {TempPoints: "{lat: 51.478,lng: -3.192},{lat: 51.478,lng: -3.192…{lat: 51.47840998047034,lng: -3.1926937697490536}"}
Objects need to have key:value
pairs so your desired output is not valid syntax.
It looks like you might want an array of objects:
var array = [
{
lat: 51.478,
lng: -3.192
},
{
lat: 51.478,
lng: -3.192
},
{
lat:51.47840998047034,
lng: -3.1926937697490536
}
];
Using JavaScript:
var obj = {TempPoints: "{'lat': 51.478,'lng': -3.192},{'lat': 51.478,'lng': -3.192},{'lat': 51.47840998047034,'lng': -3.1926937697490536}"};
var obj = "["+obj.TempPoints+"]";
var newObj = eval(obj);
console.log(newObj); //It's an array of Objects
echo json_encode($row['TempPoints']);
Is this what you want?