0

is it possible?

basically i'm a trying to achieve something like this

 JSON.stringify("address=",Obj_address,Obj_city,Obj_state,Obj_zip)

after stringify

to become like

address= "Address city state zip"

in a string like fashion. Reason being is I'm trying to pass this string into my google geocoding url api.

I played around and it so far only 1 parameter can be passed.

Help appreciated and thanks

3
  • 1
    why aren't you doing something like JSON.stringify({address:Obj_address, city:Obj_city, state:Obj_state, zip:Obj_zip});? Commented Aug 4, 2014 at 7:21
  • 1
    Your example isn't JSON; JSON uses : between names and values, not =. Commented Aug 4, 2014 at 7:22
  • @david actually, can i then pass the key into api url? im doing google geocoding to get the coordinates Commented Aug 4, 2014 at 7:29

2 Answers 2

1

This would be better.

var str = 'address="'+[Obj_address,Obj_city,Obj_state,Obj_zip].join(' ')+'"';

But you probaby don't need the quotes.

var str = 'address='+encodeURIComponent(
    [Obj_address,Obj_city,Obj_state,Obj_zip].join(' '));

Or according to the api with a plus separator.

var str = 'address='+encodeURIComponent(
    [Obj_address,Obj_city,Obj_state,Obj_zip].join('+'));
Sign up to request clarification or add additional context in comments.

Comments

0

You need to try like this one

alert("address=" + JSON.stringify(Obj_address) + " " + JSON.stringify(Obj_city) + " " + JSON.stringify(Obj_state) + " " + JSON.stringify(Obj_zip));

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.