js解析网络中的json数据

<?php
echo <<<_END
<html>
<head>
</head>
<body>
<div id="container"></div>

<script> 
//var value2 = {"list":[ {"password":"1230","username":"coolcooldool"}, {"password":"thisis2","username":"okokok"}], "array":[{"password":"1230","username":"coolcooldool"},{"password":"thisis2","username":"okokok"}]};  
// 
//var obj2 = eval(value2);  
//alert(obj2.list[0].password);
var getJSON = function(url) {
      return new Promise(function(resolve, reject) {
        var xhr = new XMLHttpRequest();
        xhr.open('get', url, true);
        xhr.responseType = 'json';
        xhr.onload = function() {
          var status = xhr.status;
          if (status == 200) {
            resolve(xhr.response);
          } else {
            reject(status);
          }
        };
        xhr.send();
      });
    };

    getJSON('http://web.cellpies.com/api/driving/getVehicleLocationPoints?vehicleDeviceId=0400000000030603&timeType=4&startTime=2017-03-17%2013:00:00&stopTime=2017-03-17%2014:00:00').then(function(jdata) {
        alert('Your Json result is:  ' + jdata); //you can comment this, i used it to debug
        alert(jdata.data[0].gpsx);
        alert(jdata.data[0].gpsy);
        
       
    }, function(status) { //error detection....
      alert('Something went wrong.');
    });
</script> 


_END;
 

?>

json数据格式为

 
  

{
"retcode": 1,
"data": [
{
"time": "2017-03-17 13:15:00",
"longitudedegree": null,
"longitudeminute": null,
"longitudesecond": null,
"longitudedecimals": null,
"latitudedegree": null,
"latitudeminute": null,
"latitudesecond": null,
"latitudedecimals": null,
"gpsx": "126.60580555556",
"gpsy": "45.702363888889"
},
{
"time": "2017-03-17 13:15:01",
"longitudedegree": null,
"longitudeminute": null,
"longitudesecond": null,
"longitudedecimals": null,
"latitudedegree": null,
"latitudeminute": null,
"latitudesecond": null,
"latitudedecimals": null,
"gpsx": "126.60573055556",
"gpsy": "45.702355555556"
}
]
}

 

转载于:https://www.cnblogs.com/vactor/p/6680866.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值