javascript - 使用 AppleScript 和 JSON 解析数据时出错

标签 javascript json xml applescript

你好, 我正在尝试使用 appleScriptJSON 帮助程序解析一些数据,
特别是尝试获取 image 属性的 src 值。

 tell application "JSON Helper"
    -- fetch the JSON
    set wallpaperJson to fetch JSON from "https://glowing-torch-5096.firebaseio.com//kimono/api/95cifi2g/latest.json"

    -- pull out the URL
    set wallpaperUrl to src of image of model of results of wallpaperJson

结果,

error "Can’t get image of {{image:{alt:\"April by Rich Cutrone on 500px\", src:\"https://drscdn.500px.org/photo/141047085/q%3D80_h%3D300/fa5a7f61529d6e30a31c04edc63ccdec\"}}}." number -1728 from image of {{image:{alt:"April by Rich Cutrone on 500px", src:"https://drscdn.500px.org/photo/141047085/q%3D80_h%3D300/fa5a7f61529d6e30a31c04edc63ccdec"}}}

这里是源JSON:

{"count":1,"lastrunstatus":"success","name":"500HDPic","newdata":true,"results":{"model":[{"image":{"alt":"April by Rich Cutrone on 500px","src":"https://drscdn.500px.org/photo/141047085/q%3D80_h%3D300/fa5a7f61529d6e30a31c04edc63ccdec"}}]},"thisversionrun":"Mon Feb 22 2016 02:26:31 GMT+0000 (UTC)","thisversionstatus":"success","version":1}

enter image description here

任何帮助将不胜感激。 谢谢!

最佳答案

由于模型是一个包含记录的列表,因此脚本必须获取模型中的第一项。

像这样:

set wallpaperJson to {thisversionrun:"Mon Feb 22 2016 02:26:31 GMT+0000 (UTC)", |count|:1, results:{model:{{image:{alt:"April by Rich Cutrone on 500px", src:"https://drscdn.500px.org/photo/141047085/q%3D80_h%3D300/fa5a7f61529d6e30a31c04edc63ccdec"}}}}, newdata:true, thisversionstatus:"success", |version|:1, lastrunstatus:"success", |name|:"500HDPic"}

set wallpaperUrl to src of image of item 1 of (model of results of wallpaperJson)

关于javascript - 使用 AppleScript 和 JSON 解析数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35545789/

相关文章:

json - R:JSON 向量到 data.frame

java - 没有内部类的 Json Jackson 反序列化

android - 将 xml 导入另一个 xml

xml - 生成没有 .xsd 的 POJO?

java - 无法在另一个 Activity 中使用另一个布局元素 - android studio

javascript - 单击时显示/隐藏 Div(许多 Div)

javascript - 获取 Angular ng-option 中的选定值

javascript - 检查样式表是否加载然后渲染元素

javascript - 将一个图像拖到另一个图像上并将其保存为一个图像(如光增强现实)

java - ClassCastException 将字符串解析为 JSONArray