JavaScript object data extraction (JSON Stringify/Parse or without?) -
i trying figure out if json.stringify object this:
{"m_id":"xxx","record": {"user":"yyy","pwd","zzz","_createdat": 11111."_updatedat":00000},"state":"valid"}
and try json.parse out user , pwd, not have call object, go through stringify. how work?
thanks.
i'm not sure why you're talking stringifying object. you'd stringify if needed send data across network or something, not when need manipulate in js.
...how extract strings in
{...user: "aaa", pwd: "zzz"...}
?
assuming have variable referring object, following (with or without nice line breaks , indenting make readable, , or without quotes around property names):
var obj = { "m_id": "xxx", "record": { "user": "yyy", "pwd" : "zzz", "_createdat": 11111, "_updatedat": 00000 }, "state": "valid" };
then can access properties in nested record
object follows:
console.log( obj.record.user ); // outputs "yyy" console.log( obj.record.pwd ); // outputs "zzz" // etc.
(note: in question had 2 typos, comma should've been colon in between "pwd"
, "zzz"
, , dot should've been comma in between 11111
, "_updatedat"
. there's no way json.stringify()
have produced string showed mistakes.)
Comments
Post a Comment