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条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行