最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - parsing complex json jquery - Stack Overflow

programmeradmin0浏览0评论

I'm trying to getJSON the following json data:

{
  "count": 96,
  "value": {
    "title": "cotripWeatherStations",
    "description": "Pipes Output",
    "link": "http:\/\/pipes.yahoo\/pipes\/pipe.info?_id=f43ccc14ab9d1c88d537236e93c1525e",
    "pubDate": "Mon, 03 Sep 2012 02:17:48 +0000",
    "generator": "http:\/\/pipes.yahoo\/pipes\/",
    "callback": "",
    "items": [
      {
        "ws:Location": {
          "global:Latitude": "37.086807",
          "global:Longitude": "-104.521294"
        },
        "ws:Device": {
          "global:DeviceId": "6796",
          "global:CommonName": "025N008  RATON PASS (RWIS)",
          "global:Status": "enabled",
          "global:EntityId": "1",
          "global:RoadId": "31",
          "global:RoadName": "I-25",
          "global:Direction": "North",
          "global:MileMarker": "8",
          "global:LastUpdateDate": "2012-08-26T13:52:00.000-06:00",
          "global:Icon": "theme\/cotrip\/images\/devices\/icon_device_weather_station_with_cam_16x23.gif"
        }
      }
   ]
}

the following code gives me an alert with output, but no data:

var weather = $.getJSON(".run?_id=f43ccc14ab9d1c88d537236e93c1525e&_render=json&_callback=?", function(json) {
  alert("JSON Data: " + json.value["items"]);
});

how do I traverse further into this JSON to 'ws:Devise - "global:CommonName"

I'm trying to getJSON the following json data:

{
  "count": 96,
  "value": {
    "title": "cotripWeatherStations",
    "description": "Pipes Output",
    "link": "http:\/\/pipes.yahoo.\/pipes\/pipe.info?_id=f43ccc14ab9d1c88d537236e93c1525e",
    "pubDate": "Mon, 03 Sep 2012 02:17:48 +0000",
    "generator": "http:\/\/pipes.yahoo.\/pipes\/",
    "callback": "",
    "items": [
      {
        "ws:Location": {
          "global:Latitude": "37.086807",
          "global:Longitude": "-104.521294"
        },
        "ws:Device": {
          "global:DeviceId": "6796",
          "global:CommonName": "025N008  RATON PASS (RWIS)",
          "global:Status": "enabled",
          "global:EntityId": "1",
          "global:RoadId": "31",
          "global:RoadName": "I-25",
          "global:Direction": "North",
          "global:MileMarker": "8",
          "global:LastUpdateDate": "2012-08-26T13:52:00.000-06:00",
          "global:Icon": "theme\/cotrip\/images\/devices\/icon_device_weather_station_with_cam_16x23.gif"
        }
      }
   ]
}

the following code gives me an alert with output, but no data:

var weather = $.getJSON("http://pipes.yahoo./pipes/pipe.run?_id=f43ccc14ab9d1c88d537236e93c1525e&_render=json&_callback=?", function(json) {
  alert("JSON Data: " + json.value["items"]);
});

how do I traverse further into this JSON to 'ws:Devise - "global:CommonName"

Share Improve this question edited Sep 3, 2012 at 3:01 kinakuta 9,0371 gold badge40 silver badges48 bronze badges asked Sep 3, 2012 at 2:58 Loghome FinishingLoghome Finishing 131 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

How about

json.value.items[0]['ws:Device']['global:CommonName']

?

http://jsfiddle/zerkms/D2JKR/

发布评论

评论列表(0)

  1. 暂无评论