Re: Tearing my bloody hair out.


Brian Christmas
 

Sorry about all this noise!

I’ve just realized something, but I don’t know the answer to my understanding.

When I posted the below Script 2, I’d added 'as list’ to the end of….. 

set temp to {action:"subscription.getall", result:"success", page:1, limit:10000, nextPage:nulltotal:1, subscriptions:["f-DfdENtRvuhBtKJUIA8QQ"]} as list

THIS ACTUALLY FAILS. Which leads me to understand without the ‘as list', I’ve actually got an applescript Record in Script 2 (please correct me if I’m wrong) The Record WORKS! (bofere I added ‘as list’)

HOWEVER, in Script 1, the list is actually text, NOT A RECORD, and fails. Problem is, even after reading Shanes Explored, I can’t find a way of converting the text to a Record.

I’ve Googled, found nothing. 

How can I change the text to an Applescript Record? I HAVE to change the original to text to apply Delimiters, to get rid of the quotations. The information is there, just in the wrong format.

OR, is there an easier way?

Regards

Santa


 
Further to this matter

I had realized that the fact that the keys were in Quotes in jsonURL meant that it wasn’t really a Dictionary, but thought there might be some simple way to change it, so posted.

But, no fast answers, so after thinking, wrote the following Script 1

However, it’s not recognized still as a Dictionary, and I don’t know why. If I take the EXACT list, and use it in Script 2, it works fine.

There’s obviously something I’m missing, but I thought coercing temp to a list would fix any hassles.

BTW, I’ve tried stripping the square brackets as text item delimiters, but it fails.

Anybody able to set me straight, please?

Regards

Santa


SCRIPT 1

use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions


set jsonURL to do shell script "curl --verbose -A UserAgentString -u 2V57JR9HQNAZNZVOW6OZXG:my-password   https://api.fastspring.com/subscriptions?limit=10000"
set temp to jsonURL as text
set OLD_delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "{\""
set temp to text items of temp
set AppleScript's text item delimiters to "{"
set temp to text items of temp as text
set AppleScript's text item delimiters to ",\""
set temp to text items of temp
set AppleScript's text item delimiters to ","
set temp to text items of temp as text
set AppleScript's text item delimiters to "\":"
set temp to text items of temp
set AppleScript's text item delimiters to ":"
set temp to text items of temp as text
set AppleScript's text item delimiters to OLD_delim
set temp to temp as list
display dialog temp --< Returns "{action:"subscription.getall",result:"success",page:1,limit:10000,nextPage:null,total:1,subscriptions:["f-DfdENtRvuhBtKJUIA8QQ"]}"
try
set numbersDict to current application's NSDictionary's dictionaryWithDictionary:temp
on error errmsg
display dialog errmsg --<  returns   "*** -[NSDictionary initWithDictionary:copyItems:]: dictionary argument is not an NSDictionary"
end try
try
set subscriptionsList to temp's subscriptions as list
end try
subscriptionsList
SCRIPT 2

use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions

set temp to {action:"subscription.getall", result:"success", page:1, limit:10000, nextPage:null, total:1, subscriptions:["f-DfdENtRvuhBtKJUIA8QQ"]} as list
try
set numbersDict to current application's NSDictionary's dictionaryWithDictionary:temp
on error errmsg
display dialog errmsg --< no error
end try
try
set subscriptionsList to numbersDict's subscriptions as list
on error errmsg
display dialog errmsg --<  returns   "*** -[NSDictionary initWithDictionary:copyItems:]: dictionary argument is not an NSDictionary"
end try
subscriptionsList --< WORKS! Returns "f-DfdENtRvuhBtKJUIA8QQ"

Join applescript@apple-dev.groups.io to automatically receive all group messages.