doujiaoang69440 2013-10-28 22:01
浏览 38
已采纳

从API到数组的外部JSON?

Ok, I have a JSON file from a website API that I need to re-arrange so the data can be read by Highcharts. I do not know how to proceed. I have a URL and from reading the docs on highcharts website, I need to re-format the data to be used correctly, so, how should I proceed?

Should I set up a php file that loads the JSON file, then use javascript to pick out what I want? If so, how would I accomplish this?

Thanks in advance!

Here is an example of the JSON data

[
  {
    "timestamp": 1382918400,
    "localTimestamp": 1382918400,
    "issueTimestamp": 1382918400,
    "fadedRating": 4,
    "solidRating": 0,
    "swell": {
      "minBreakingHeight": 5,
      "absMinBreakingHeight": 4.508,
      "maxBreakingHeight": 7,
      "absMaxBreakingHeight": 7.049,
      "unit": "ft",
      "components": {
        "combined": {
          "height": 18,
          "period": 10,
          "direction": 37.25,
          "compassDirection": "SW"
        },
        "primary": {
          "height": 18,
          "period": 10,
          "direction": 47.09,
          "compassDirection": "SW"
        }
      }
    },
    "wind": {
      "speed": 15,
      "direction": 79,
      "compassDirection": "W",
      "chill": 54,
      "gusts": 29,
      "unit": "mph"
    },
    "condition": {
      "pressure": 986,
      "temperature": 59,
      "weather": "23",
      "unitPressure": "mb",
      "unit": "f"
    },
    "charts": {
      "swell": "http://chart-1.msw.ms/wave/750/1-1382918400-1.gif",
      "period": "http://chart-1.msw.ms/wave/750/1-1382918400-2.gif",
      "wind": "http://chart-1.msw.ms/gfs/750/1-1382918400-4.gif",
      "pressure": "http://chart-1.msw.ms/gfs/750/1-1382918400-3.gif",
      "sst": "http://chart-1.msw.ms/sst/750/1-1382918400-10.gif"
    }
  },
]
  • 写回答

2条回答 默认 最新

  • douyi1982 2013-10-29 12:36
    关注

    You need to parse your JSON i.e in javascript, by prepareing correct structure

    series: [{
                name: 'Tokyo',
                data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
            }]
    

    and use it like

    series: customSeries
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?