0

I am really confused here. I have the result string

{ "member_id":"5", "msg":"login successful", "type_id":"1" }

and I want to get a single value like

 alert(member_id);
 alert(msg);
 alert(type_id);
0

2 Answers 2

3

i have result string { "member_id":"5", "msg":"login successful", "type_id":"1" }

  1. Convert it to a JSON object with JSON.parse
  2. Access members with either . or [] notation

var objStr = '{ "member_id":"5", "msg":"login successful", "type_id":"1" }';

var obj = JSON.parse(objStr);


document.write(obj.member_id);

document.write(obj['member_id']);

Sign up to request clarification or add additional context in comments.

Comments

0
var obj = { "member_id":"5", "msg":"login successful", "type_id":"1" }
console.log(obj.member_id)

1 Comment

It's a string, not a parsed object.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.