Hi iam trying to store this JSON to my javascript array.Is there any way to that.am using following code and its not working at all.
my json JSON
[{"id":"1","Intensity":"1","Location":"12.48,77.26"},{"id":"2","Intensity":"2","Location":"12.47,77.26"},{"id":"3","Intensity":"2","Location":"12.47,77.27"},{"id":"4","Intensity":"2","Location":"12.46,77.24"},{"id":"5","Intensity":"2","Location":"12.44,77.24"},{"id":"6","Intensity":"2","Location":"12.44,77.28"},{"id":"7","Intensity":"2","Location":"12.50,77.28"},{"id":"8","Intensity":"2","Location":"12.45,77.30"},{"id":"9","Intensity":"2","Location":"12.41,77.21"}]
my html code with JS for getting json data
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.0.min.js"></script>
</head>
<body>
<div id="response">werer</div>
<script>
$.get('http://zonewebs.org/website/naveen/source/location.php', function(data) {
$('#response').append(data);
});
</script>
</dody>
</html>
Use JSON.parse to convert valid json to javascript array
var dataArray = JSON.parse(data);
Your json is not valid.Try jsonlint. Remove this from the end :
{"var":"stuff"}
Then use :
JSON.parse(data);