1

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

1 Answer 1

1

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.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.