Reputation: 457
I have a URL like that and I want to use JSON data coming inside URL
"CUNMXSAKU" : {
"roomCodes" : "DEAL, JRST, JPOV, JSSW, PJRS, PJOV, PJSW, RMOV, RMOF, PRES"
},
My URL
...._results.html?language=en&hotelInfo={CUNMXSAKU:{roomCodes:DEAL,JRST,JPOV,JSSW,PJRS,PJOV,PJSW,RMOV,RMOF,PRES}}
Is it possible to use it ?? I am able to get var hotelCode = getQueryParameter('hotelInfo'); as a String
{"CUNMXSAKU":{"roomCodes":"DEAL, JRST, JPOV, JSSW, PJRS, PJOV, PJSW, RMOV, RMOF, PRES"}}
But when I am trying hotelCode.roomCodes , its Undefined.
Please help on this. Is it possible to do with javaScript
Upvotes: 1
Views: 126
Reputation: 425
When you pull them out of the URL, the params are a string, they're not a javascript object.
Use something like this (in addition to what you have there)
var params = getQueryParameter('hotelinfo');
var hotelCode = JSON.parse(params);
Then hotelCode will actually contain a proper, walkable javascript object.
Upvotes: 1