问题描述
{ "Response": { "Head": { "ChuFaZhan": { "CheZhanBianHao": "3ea57ec8-15ce-4574-b341-8e06e0c747b0", "CheZhanBianMa": "1051033288", "CheZhanMingCheng": "北京" }, "DaoDaZhan": { "CheZhanBianHao": "3e8b13db-f1ad-459d-97c2-02838c92293c", "CheZhanBianMa": "1049301979", "CheZhanMingCheng": "乌鲁木齐" } }, "Main": { "@Rows": "3", "Item": [ { "@Id": "1", "CheCiBianHao": "c1cd4185-4a15-4c18-aee4-883f9f0a814f", "CheCiBianMa": "1043512955", "CheCiMingCheng": "T69", "CheXingMingCheng": "空调特快", "ShiFaZhan": "北京西", "ChuFaZhan": "北京西", "DaoDaZhan": "乌鲁木齐", "ZhongDianZhan": "乌鲁木齐", "FaShi": "10:01", "DaoShi": "20:33", "LiShi": "24:31", "LiCheng": "0", "ShangWuZuo": "--", "TeDengZuo": "--", "YiDengZuo": "--", "ErDengZuo": "--", "GaoJiRuanWoShang": "--", "GaoJiRuanWoXia": "--", "RuanWoShang": "834.50", "RuanWoXia": "871.50", "YingWoShang": "529.50", "YingWoZhong": "547.50", "YingWoXia": "566.50", "RuanZuo": "--", "YingZuo": "313.50" }, { "@Id": "2", "CheCiBianHao": "697fae0b-e7a1-4b3e-8b22-631cd016df8d", "CheCiBianMa": "1769975307", "CheCiMingCheng": "T177/T178", "CheXingMingCheng": "空调特快", "ShiFaZhan": "北京", "ChuFaZhan": "北京", "DaoDaZhan": "乌鲁木齐", "ZhongDianZhan": "乌鲁木齐", "FaShi": "15:18", "DaoShi": "07:39", "LiShi": "25:03", "LiCheng": "0", "ShangWuZuo": "--", "TeDengZuo": "--", "YiDengZuo": "--", "ErDengZuo": "--", "GaoJiRuanWoShang": "--", "GaoJiRuanWoXia": "--", "RuanWoShang": "849", "RuanWoXia": "887", "YingWoShang": "536", "YingWoZhong": "555", "YingWoXia": "575", "RuanZuo": "--", "YingZuo": "317" }, { "@Id": "3", "CheCiBianHao": "8ec6a757-ed6b-4066-8900-d191c263dd21", "CheCiBianMa": "1899583657", "CheCiMingCheng": "T177", "CheXingMingCheng": "空调特快", "ShiFaZhan": "北京", "ChuFaZhan": "北京", "DaoDaZhan": "乌鲁木齐", "ZhongDianZhan": "乌鲁木齐", "FaShi": "15:18", "DaoShi": "07:39", "LiShi": "25:03", "LiCheng": "0", "ShangWuZuo": "--", "TeDengZuo": "--", "YiDengZuo": "--", "ErDengZuo": "--", "GaoJiRuanWoShang": "--", "GaoJiRuanWoXia": "--", "RuanWoShang": "849", "RuanWoXia": "887", "YingWoShang": "536", "YingWoZhong": "555", "YingWoXia": "575", "RuanZuo": "--", "YingZuo": "317" } ] }, "Foot": { "Time": "589.57", "Site": "http://www.twototwo.cn", "Json": "{"format":"json","action":"QueryTrainScheduleByTwoStation","key":"49a9ee9a-7db3-4241-9342-9838bec40b0b","startStation":"%e5%8c%97%e4%ba%ac","arriveStation":"%e4%b9%8c%e9%b2%81%e6%9c%a8%e9%bd%90","startDate":"2014-03-06","ignoreStartDate":"0","like":"1","more":"0"}", "Info": "{"format":"json","action":"QueryTrainScheduleByTwoStation","key":"49a9ee9a-7db3-4241-9342-9838bec40b0b","startStation":"北京","arriveStation":"乌鲁木齐","startDate":"2014-03-06","ignoreStartDate":"0","like":"1","more":"0"}" } }}
解决方案
Head里面存放的是出发站及到站信息.Main里中 1、(@Rows ) 共有几条记录 2、(Item) 车辆信息集合.大概有车次,发车时间,到达时间等.Foot里面可能是一些时间信息,或翻页信息.(没有仔细不太确定了.)
解决方案二:
请用 $.parseJSON(testJson); 少用eval。容易引发安全问题!
解决方案三:
js 字符串转json? function strToJson(str){ var json = eval('(' + str + ')'); return json; }testJson = $.parseJSON(testJson); alert(testJson.name);