-1

我从 AJAX 查询中得到了这样的字符串:

var ansverStr = "[1,\"贝德福德街\",\"牛津马戏团、格林公园或威斯敏斯特\",\"15\",\"摄政街\",1343329406000]\r\n[1,\" Bedford Street\",\"Oxford Circus, Green Park or Westminster\",\"13\",\"Golders Green\",1343329883000]\r\n[1,\"Bedford Street\",\"Oxford Circus , Green Park or Westminster\",\"176\",\"Tottenham Ct Rd\",1343329612000]\r\n[1,\"Bedford Street\",\"Oxford Circus, Green Park or Westminster\", \"91\",\"Trafalgar Sq\",1343329514000]\r\n[1,\"Bedford Street\",\"Oxford Circus, Green Park or Westminster\",\"11\",\"Fulham百老汇\",1343329434000]\r\n[1,\"贝德福德街\",\"牛津马戏团,格林公园或威斯敏斯特\",\"87\",\"Wandsworth\",1343330102000]\r\n[1,\"贝德福德街\",\"牛津马戏团、格林公园或威斯敏斯特\",\"6 \",\"Willesden Gar\",1343329673000]\r\n[1,\"Bedford Street\",\"Oxford Circus, Green Park or Westminster\",\"91\",\"Trafalgar Sq\" ,1343329871000]\r\n[1,\"Bedford Street\",\"Oxford Circus, Green Park or Westminster\",\"11\",\"Fulham Broadway\",1343329743000]"格林公园或威斯敏斯特\",\"91\",\"特拉法加广场\",1343329871000]\r\n[1,\"贝德福德街\",\"牛津马戏团,格林公园或威斯敏斯特\",\" 11\",\"富勒姆百老汇\",1343329743000]"格林公园或威斯敏斯特\",\"91\",\"特拉法加广场\",1343329871000]\r\n[1,\"贝德福德街\",\"牛津马戏团,格林公园或威斯敏斯特\",\" 11\",\"富勒姆百老汇\",1343329743000]"

然后为它创建了一个动态表

变量元素;

element = '' + ansverStr.split('\r\n').map(function(line){ return '' + JSON.parse(line).map(function(cell){ return '' + cell + '' ; }).join('') + ''; }).join('') + ''; document.getElementById("bStop").innerHTML=element;

ansverStr 子字符串中的最后一个字段是时间。

问题:如何访问动态表中的这些值以将它们转换为时间格式

4

1 回答 1

0

使用正确的 Json 格式将使检索结果变得非常简单http://jsfiddle.net/wzBFC/1/

var myJSONObject = {"results": [
     {"street_number": 1,"street":"Bedford Street","city":"Oxford Circus, Green Park or Westminster","address2":"15","street2":"Regent  Street","timestamp":1343329406000},
     {"street_number": 1,"street":"Bedford Street","city":"Oxford Circus, Green Park or Westminster","address2":"15","street2":"Regent  Street","timestamp":1343329407000}
     ] };    

     timeStamp = new Date(myJSONObject.results[1].timestamp);    
     alert(timeStamp);
于 2012-07-26T19:59:54.940 回答