I create a JSON string whith dynamical values which looks like this:
我创建一个JSON字符串动态值如下所示:
{"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?
栈溢出的可能解决方案对我不起作用。有人给我提建议吗?
1 个解决方案
#1
1
Get rid of toFixed(6)
to stop converting the numbers to String:
去掉toFixed(6),停止将数字转换为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);
#1
1
Get rid of toFixed(6)
to stop converting the numbers to String:
去掉toFixed(6),停止将数字转换为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);