你好,
我正在尝试使用appleScript
和JSON
助手来解析一些数据,
专门尝试获取src
属性的image
值。
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
结果,
错误“无法获得{{image:{alt:\“ Rich Cutrone 4月在500px上的图片”,src:\” https://drscdn.500px.org/photo/141047085/q%3D80_h%3D300/fa5a7f61529d6e30a31c04edc63ccdec \“}}}}。” {{image:{alt:“ Rich Cutrone于4月发表,像素为500px”,src:“ https://drscdn.500px.org/photo/141047085/q%3D80_h%3D300/fa5a7f61529d6e30a31c04edc63ccdec”}}}中的数字-1728
这里的源
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}
任何帮助将不胜感激。
谢谢!
最佳答案
因为模型是一个包含记录的列表,所以脚本必须获取模型中的第一项。
像这样:
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)