Ben Mustapha Sabrine Ben Mustapha Sabrine - 5 months ago 10
JSON Question

get data from json to JavaScript?

var Point = {
"id": 1,
"name": "A",
"LastUpdate": [36.8474448, 10.2793222],
"position": [36.8479648, 10.2793332]
}


here is my json code, i need to access to that object from a javascript file.
I am not familiar with JSON, please help.

Answer

You can use this code.

     var Point = {

"id": 1,
"name": "A",
"LastUpdate": [36.8474448, 10.2793222],
"position": [36.8479648, 10.2793332]}
var str = JSON.parse(Point);

and you are also do stringify for get json data in string format.

    function replacer(key, value) {
    if ( key === '' || typeof value === "string") {
        return value;
    }
    return undefined;
}

    var str2 = JSON.stringify(message, replacer);
   console.log(str2 );
Comments