“JS Stringify” Kode Jawaban

Ubah objek menjadi string javascript

var obj = {a: "a", b: "b" /*...*/};
var string = JSON.stringify(obj);
// OUTPUT:
// "{'a':'a', 'b':'b'}"
Vbbab

Node Json Stringify

let data = {
  name: "John Smith",
  age: 30,
  hobbies: ["Programming", "Video Games"]
};

// {name:"John Smith",age:30,hobbies:["Programming","Video Games"]}
let miny = JSON.stringify(data);

// The 4 parameter signifys 4 spaces. You can also use "\t".
/* {
 *     name: "John Smith",
 *     age: 30,
 *     ...
 */
let pretty = JSON.stringify(data, null, 4);
Nathan uses Linux

Objek javascript ke string json

var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person); 
Grepper

string js ke json

var obj = JSON.parse("{no:'u',my:'sql'}");//returnes {no:'u',my:'sql'}
If-dev

JavaScript Stringy dengan fungsi

function stringifyWithFunctions(object) {
  return JSON.stringify(object, (key, val) => {
    if (typeof val === 'function') {
      return `(${val})`; // make it a string, surround it by parenthesis to ensure we can revive it as an anonymous function
    }
    return val;
  });
};

function parseWithFunctions(obj) {
  return JSON.parse(obj, (k, v) => {
    if (typeof v === 'string' && v.indexOf('function') >= 0) {
      return eval(v);
    }
    return v;
  });
};
Arrogant Anteater

JS Stringify

Turn JS object or value into string
Haruki

Jawaban yang mirip dengan “JS Stringify”

Pertanyaan yang mirip dengan “JS Stringify”

Lebih banyak jawaban terkait untuk “JS Stringify” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya