简体   繁体   English

如何从指向Java脚本数组的链接存储JSON?

[英]How do i store JSON from a link to java script array?

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. 嗨,iam试图将这个JSON存储到我的javascript数组中。使用下面的代码有什么方法可以做到那吗?

my json JSON 我的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 我的JS html代码获取json数据

<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>

使用JSON.parse将有效的 json转换为javascript数组

var dataArray = JSON.parse(data);

Your json is not valid. 您的json无效。 Try jsonlint . 尝试jsonlint Remove this from the end : 从最后删除此:

{"var":"stuff"}

Then use : 然后使用:

JSON.parse(data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM