I have a string:
"{0:16970861903381446063,length:1}"
I tried converting it to an object using the eval
method, but it also evaluates the string and hence rounds the numerical value, returning:
{0:16970861903381447000,length:1}
I tried passing the number as a string before calling eval
on it,
using 16970861903381446063 + ''
as the value when creating the JSON string; checking it with typeof
shows it as being of type string
, but it still rounds the number 16970861903381446063 to 16970861903381447000.
Is there a way I can bypass this, or a better way to do this?
Following is the code that generates the json text from an array containing the numbers
function simplify(arr){
request = "{";
if (arr.length ==1){
request += 0 + ":" + (arr[0] + '') + "," ;
}
else{
for (var i=0;i<=arr.length-1 ;i++){
request += i + ":" + (arr[i] + '') + ",";
}
}
request += "length" + ":" + arr.length +"}";
return request;
}