“JS Stringify” Code-Antworten

Verwandeln Sie das Objekt in String JavaScript

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

Knoten 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

JavaScript -Objekt zu JSON String

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

JS String to JSON

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

JavaScript Stringify mit Funktionen

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

Ähnliche Antworten wie “JS Stringify”

Fragen ähnlich wie “JS Stringify”

Weitere verwandte Antworten zu “JS Stringify” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen