0
my obj = {
    "formname": ["appname", {
        "operation": ["add", {
            "values": {
                "Activation_code": "12345",
                "ID": 722756000010586033,
                "game_Id": "10000"
            },
            "status": "Success"
        }]
    }]
}

The above code is my object from a server I have no problem getting the value the point am making is why JSON.parse(obj) is changing the ID after the object as gone through its function.

hence after a parse it spits back the ID as 722756000010586000 Why?

coder
  • 1

1 Answers1

0

Cos of number precision, your id is way past max safe integer, I suggest keeping it as string.

console.log(722756000010586033 > Number.MAX_SAFE_INTEGER)
console.log(722756000010586033);

Basically there is some finite memory used to store numbers in JS and with finite momory comes finite number of digits that can be remember. This is ofc a little bit more complicated than that, but that is basically it.

You can extract your id with regular expression:

const JSON = `{
    "formname": ["appname", {
        "operation": ["add", {
            "values": {
                "Activation_code": "12345",
                "ID": 722756000010586033,
                "game_Id": "10000"
            },
            "status": "Success"
        }]
    }]
}`;

const matched = JSON.match(/"ID":\s*(\d+),/);
const id = matched[1];

document.body.innerHTML = id;
sielakos
  • 2,406
  • 11
  • 13
  • Can I ask? this ID it comes from a zoho service so I have no control over it what do you suggest? I was thinking if i could stringify it the access it from there @sielakos – coder May 29 '16 at 05:10
  • @coder sure, you can extract id with regular expression, here you go https://jsfiddle.net/n04g3e77/ – sielakos May 29 '16 at 05:14
  • Okay I tried somthing but still no luck look @ https://jsfiddle.net/tehatrcy/ @sielakos – coder May 29 '16 at 05:33
  • Got it to work thanks man I use the toString method – coder May 29 '16 at 05:55