0

im very new to getting data from one page to another and i have used querystring to pass data. and looks like this:

?redesigndata={"jsondata": "{\"images\":[ {\"src\":\"images/bgset.jpg\"},{\"src\":\"images/ar019.png\"}]}","product_hardware": "silver","product_thread": "white","product_lining": "Blue","product_lining_loc": "images/lining/blue_80x32.jpg"}

How do i remove all the \ from it and then put it into an object or any thing like this with Javascript or jQuery:

redesigndata = {
    "jsondata": "{"images":[ {"src":"images/bgset.jpg"},{"src":"images/ar019.png"}]}",
    "product_hardware": "silver",
    "product_thread": "white",
    "product_lining": "Blue",
    "product_lining_loc": "images/lining/blue_80x32.jpg"
}
1
  • 1
    $.param Commented Jul 12, 2012 at 17:47

2 Answers 2

2

location.search will get you the querystring (starting with the ?). Strip off the ?, split it at =, then JSON.parse it.

var jsonStr = location.search.substring(1).split('=');
var obj = JSON.parse(unescape(jsonStr[1]));

Then you can parse jsondata.

var jsondata = JSON.parse(obj.jsondata);
Sign up to request clarification or add additional context in comments.

Comments

2

Why would you remove those backslashes? Without them you the JSON wouldn't be valid anymore. Right now you have nested JSON so you can parse it like this (with str being the redesigndata value):

var redesigndata = JSON.parse(JSON.parse(str).jsondata);

1 Comment

i didnt know the back slashes were important. Thanks

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.