wuk986
wuk986

Reputation: 142

Remove double quotes from JSON string value

I create a JSON string whith dynamical values which looks like this:

{"geometry": {"type": "Point", "coordinates": ["78.454", "22.643"]}, "type": "Feature", "properties": {"Number":"123","Plate":"xxx","Position":"xyz",}}

the dynamical values are the coordinates and the values in the properties.

the code to create the string is the following:

var tmpLlrtArr = [];
$.each(data, function(key, value) {
var tmpLlrtObj = {};
            tmpLlrtObj.type = 'Feature';
            tmpLlrtObj.geometry = {};
            tmpLlrtObj.geometry = {};
            tmpLlrtObj.geometry.type = 'Point';
            tmpLlrtObj.geometry.coordinates = [(value.longitude_mdeg * 0.000001).toFixed(6), (value.latitude_mdeg * 0.000001).toFixed(6)];
            tmpLlrtObj.properties = {};
            tmpLlrtObj.properties.Number = value.objectno;
            tmpLlrtObj.properties.Plate = value.objectname;
            tmpLlrtObj.properties.Position = value.postext_short;

            tmpLlrtArr.push(tmpLlrtObj);
});

var llrealTimeJSONString = JSON.stringify(llrealTimeObj);
    console.log(llrealTimeObj);

know I have the problem that, the coordinates are under double quotes and I have no idea how to remove only them.

the possible solutions here on stack overflow doesn't work for me. has anybody an advice for me?

Upvotes: 2

Views: 2229

Answers (1)

Dinei
Dinei

Reputation: 5444

Get rid of toFixed(6) to stop converting the numbers to String:

var tmpLlrtArr = [];
$.each(data, function(key, value) {
var tmpLlrtObj = {};
            tmpLlrtObj.type = 'Feature';
            tmpLlrtObj.geometry = {};
            tmpLlrtObj.geometry = {};
            tmpLlrtObj.geometry.type = 'Point';
            tmpLlrtObj.geometry.coordinates = [(value.longitude_mdeg * 0.000001), (value.latitude_mdeg * 0.000001)];
            tmpLlrtObj.properties = {};
            tmpLlrtObj.properties.Number = value.objectno;
            tmpLlrtObj.properties.Plate = value.objectname;
            tmpLlrtObj.properties.Position = value.postext_short;

            tmpLlrtArr.push(tmpLlrtObj);
});

var llrealTimeJSONString = JSON.stringify(llrealTimeObj);
    console.log(llrealTimeObj);

Upvotes: 1

Related Questions