Brecht Valcke Brecht Valcke - 6 months ago 34
JSON Question

Fitting json data in a single query string variable

I am writing a web application to exchange contact information fast via QR.
I use a QR api wich is formatted like this:


I have json data formatted in a string, example of output:


JSON data:

{"Name":"John Diggle",
"Title":"IT Consultant",

The problem is when you put this url in the QR generator it only recognises the
parameter. I understand why this happens.

The question is is there a way using javascript to convert all this data in a string and convert it back on the recieving end?

Or does anyone know another potential fix for this problem?


You need to URL encode data with special characters you put into a URL:

var url = 'http://[myapp-url]/RecieveContact.html?Name=John%20Diggle&Title=IT%20Consultant&Organisation=testcomp&Telwork=0498553311&Telhome=&Gsm=0498553311&';

var query = 'http://.../?data=' + encodeURIComponent(url) + '&size=400x400';

This way you can represent characters like & inside a query string.