per rispondere alla domanda specifica (dopo una rapida rilettura), l'unico supporto web Applescript ha è attraverso la biblioteca URL Access Scripting
, che è solo un wrapper per il comando curl
del terminale. È un po 'buggato e non riporta tutto come dovrebbe.
Oltre a ciò, non esiste alcun supporto JSON nativo in Applescript, e farlo sarà un po 'doloroso. Per analizzare il JSON, è necessario utilizzare lo Applescript's text item delimiters
.
set mJson to "\"result\":\"success\",\"image\":\"foo\", \"name\":\"bar\"" -- get your data into a string somehow, like a function
set AppleScript's text item delimiters to {","}
set keyValueList to (every text item in mJson) as list
set AppleScript's text item delimiters to ""
(*"result":"success", "image":"foo", "name":"bar"*)
repeat with thiskeyValuePair from 1 to (count keyValueList)
set theKeyValuePair to item thiskeyValuePair of keyValueList
set AppleScript's text item delimiters to {":"}
set theKeyValueBufferList to (every text item in theKeyValuePair) as list
set AppleScript's text item delimiters to ""
set theKey to item 1 of theKeyValueBufferList
(*"result"*)
set theValue to item 2 of theKeyValueBufferList
(*"success"*)
end repeat
Questo è tutto fatto quando tutto va bene. Dovrai prendere in considerazione JSON mal formato, come nel tuo esempio che contiene una virgola in più a cui non appartiene, e varianze come spazi extra e simili. Se puoi manipolare i dati altrove per ottenere quello che ti serve, ti suggerirei di farlo. Applescript non è molto buono per cose come questa.
fonte
2011-01-05 16:51:37
Non credo AppleScript ha alcun supporto nativo per questo (anche se potrei sbagliarmi), ma si può sempre usare 'fare shell script'. –