0

I am facing an issue with the JSON structure for the data I should pass to the server. Below is the required format.

 var data = '{"listingHotspots": [{"PropertyGuid": "5dc934f6-cb5a-44d4-95e6-cf7d5712359e","Hotspot": {"Coordinates": "581,391,676,391,677,410,714,410,715,562,599,562,598,527,597,473,597,409,580,407,581,391"}}]}'

My code is

 var data = {'listingHotspots':[]};
    data['listingHotspots'].push({'PropertyGuid':savedGuid,'Hotspot':    {'Coordinates':coord_string}});

This is creating a valid JavaScript object but not the one i need. I also used JSON.stringify() but it resulted in a Undefined value. Any help would be greatly appreciated.

3
  • 1
    Nothing to do with JSON. Commented Apr 20, 2012 at 2:32
  • 5
    Works for me. Commented Apr 20, 2012 at 2:32
  • 2
    @David-SkyMesh, on the contrary, he specifically asked about JSON.stringify, and he will in fact need that (or equivalent) when posting. Commented Apr 20, 2012 at 2:33

1 Answer 1

1

JSON.stringify() may not be in the target browser. If that's the case, you'll need to load json2.js. json2.js won't clobber the native JSON.stringify() if it exists, so aside from the extra request, no harm loading it all the time. See http://www.json.org/js.html and http://www.cdnjs.com/#/search/json2 and http://modernizr.com/docs/#load

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.