views:

132

answers:

3
{"loggedin":0,"error_message":"login_failed","success_message":"","username":"","sessionId":""}

this my json in string format, i have to check in javascript that loggedin value 0 or 1

+2  A: 

Do you mean:

var json = {"loggedin":0,"error_message":"login_failed","success_message":"","username":"","sessionId":""}

if(json.loggedin == 0) {
   // do something
}
else {
   // do something else
}

Update:

If you have the JSON as string, you have to parse it before you can do this. So maybe you have to do this:

var responseText = JSON.parse(responseText);
Felix Kling
that json string in resonseTextso can i do this var json=responseText;???
udhaya
@udhaya: What is *responseText*? A variable? Then you can use it directly: `responseText.loggedin`.
Felix Kling
alert(responseText);shows this{"loggedin":0,"error_message":"login_failed","success_message":"","username":"","sessionId":""}so its a string?!!
udhaya
when alert(responseText.loggedin); it shows undefined.
udhaya
@udhaya: See my updates answer.
Felix Kling
+1  A: 
var myJSONObject = {"loggedin":0,"error_message":"login_failed","success_message":"","username":"","sessionId":""};
if (myJSONObject.loggedin === 0) {
   // do something
} else {
   // do something else
}
Naeem Sarfraz
alert(responseText); shows this {"loggedin":0,"error_message":"login_failed","success_message":"","username":"","sessionId":""} when alert(responseText.loggedin); it shows undefined.
udhaya
A: 

ha ha got it, should use like this var obj = $.evalJSON(responseText); alert(obj.error_message); //output:login_failed

udhaya