ObsessiO ObsessiO - 1 year ago 77
AngularJS Question

How to extract Json object value if object name contains period?

Here is my JSON code and as u can see first object name "com.app.connect.model.Login" contain periods.

"com.app.connect.model.Login": {
"status": "FAIL",
"message": "Incorrect username or password."

I want to extract "status" value. I can get "status" value if object name doesn't contain period.

var statusJson2 = jsonCC2.comappconnectmodelLoginStatus.status;

I tried many things but I couldn't achieve.

var jsonCC = { "com.app.connect.model.LoginStatus": { "status": "FAIL", "message": "Incorrect username or password." } };

var jsonCC2 = { "comappconnectmodelLoginStatus": { "status": "FAIL", "message": "Incorrect username or password." } };

//var statusJson = jsonCC.["com.app.connect.model.LoginStatus"].status;

var statusJson2 = jsonCC2.comappconnectmodelLoginStatus.status;



Any suggestion for this?

Answer Source

You can just do:

var subObject = jsonCC["com.app.connect.model.Login"];

Don't put a period between jsonCC and [

Here is a JSFiddle of the working code.