【问题标题】:How do i use Dark Sky API with livecode?如何将 Dark Sky API 与 livecode 一起使用?
【发布时间】:2017-03-11 16:58:24
【问题描述】:

我是 livecode 的初学者,我一生都无法弄清楚如何调用 API 并使用它提供给我的数据。我已将 easyjson 脚本集成到我的堆栈中并粘贴了

" $_GET https://api.darksky.net/forecast/secretkeyhere/37.8267,-122.4233"

我什么也得不到。我可能错过了很多,但我不知道如何让它工作,我用谷歌搜索了很多,老实说,关于 livecode 的东西并不多......

我的目标是创建一个天气应用程序

【问题讨论】:

    标签: android ios json api livecode


    【解决方案1】:

    $_GET 是 LiveCode 服务器专用构造。如果您想从 LiveCode 堆栈中的 Web 服务 API 取回数据,请使用标准的 put 语句和 URL 关键字:

    put URL "https://api.darksky.net/forecast/secretkeyhere/37.8267,-122.4233" into tWeatherData
    

    这是您使用 RESTful API 执行 GET 方法的方式。要使用 POST 方法,请使用 LC post 命令:

    # first construct the argument string
    put "name=" & urlEncode("value string here") into tArgs
    post tArgs to URL "http://api.base.url"
    put it into tSomeVariable
    

    我在这里汇总了有关如何在 LiveCode 中访问 RESTful API 的课程:

    http://livecode.byu.edu/internet/webServicesIntro.php

    编辑

    下载数据后,您只需解析出要显示的内容并将其显示在文本字段中即可。对于 darksky.net,数据以 JSON 文本形式发送,因此您可以使用 LiveCode 的 JSON 库将其转换为数组。

    put JSONimport(tWeatherData) into tWeatherArray
    put tWeatherArray["currently"]["temperature"] && "degrees and" \
      && tForecastArray ["currently"]["icon"] into field "currentWeather"
    

    【讨论】:

    • 我现在已经成功地访问了 API,我获得了学位,如果它是多云晴天等,但我如何让它自动显示在卡上?现在,如果我按下一个按钮,数据就会出现在一个弹出窗口中。我确实喜欢这样:在 mouseUp 上获取 url "api.darksky.net/forecast/secreykeyhere/59.334591,18.063240" 将其放入 tForecast 将 JSONimport(tForecast) 放入 tForecastArray 回答 "It is current"&&tforecastarray[current][temperature]&&"degrees and"&&tforecastarray[current][icon]结束 mouseUp
    • 使用 answer 命令将在模式对话框中显示结果。相反,只需创建一个字段来显示天气数据。比方说,字段“currentWeather”。将answer 语句替换为put tForecastArray["currently"]["temperature"] && "degrees and" && tForecastArray ["currently"]["icon"] into field "currentWeather"
    猜你喜欢
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 2015-12-01
    • 2018-10-11
    • 2020-07-15
    • 2016-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多