I parse few data using a type class in my controller I'm getting data as follows:
{
"data":{
"userList":[
{
"id":1,
"name":"soni"
}
]
},
"status":200,
"config":{
"method":"POST",
"transformRequest":[
null
],
"transformResponse":[
null
],
"url":"/home/main/module/userlist",
"headers":{
"rt":"ajax",
"Tenant":"Id:null",
"Access-Handler":"Authorization:null",
"Accept":"application/json, text/plain, */*"
}
},
"statusText":"OK"
}
I tried to store the data like this
var userData = _data;
var newData = JSON.parse(userData).data.userList;
How can I extract the user list to a new variable?
JSON.parse
. Try usinguserData
directly as an object. – Mohit Bhardwajconsole.log(typeof userData)
showsobject
then you already have an javascript object and not a JSON string you need to parse. – t.nieseUnexpected token o in JSON
, most probably you are trying to parse an object which is already in parsed form. – Mohit Bhardwaj