“string ke objek” Kode Jawaban

Konversi String ke Object JavaScript

var mystr = '{ "hello":"world" }' // NB: Has enclosing ""
var myobj = JSON.parse(mystr);
Anxious Alligator

Javascript Parse Json

var jsonPerson = '{"first_name":"billy", "age":23}';
var personObject = JSON.parse(jsonPerson); //parse json string into JS object
Grepper

string ke objek

const json = '{ "fruit": "pineapple", "fingers": 10 }';
const obj = JSON.parse(json);
console.log(obj.fruit, obj.fingers);
Distinct Dormouse

Konversi string ke objek javascript

var mystr = '{ "hello":"world" }' // NB: Has enclosing ""
var myobj = JSON.parse(mystr);

console.log(myobj);

result:
{
  hello: "world"
}
Precious Pygmy

JSON_DECODE JavaScript

JSON.parse(jsonToDecode)
Wandering Whale

Konversi String ke Object JavaScript

str = "firstName:name1, lastName:last1"; // NB: No enclosing ""
obj = eval('({' + str + '})');
Anxious Alligator

Jawaban yang mirip dengan “string ke objek”

Pertanyaan yang mirip dengan “string ke objek”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya