Re: Newbie question re records
Re: Newbie question re records
- Subject: Re: Newbie question re records
- From: Nigel Garvey <email@hidden>
- Date: Thu, 12 Jun 2003 12:08:27 +0100
Greg Townsend wrote on Wed, 11 Jun 2003 15:26:31 -0400:
>
I have written a script using SOAP to get info from Amazon Web
>
Services. Unfortunately, I can't figure out how to extract the data
>
from the resulting record. The SOAP result comes in the form
>
{|Details|:{{|Catalog|:"DVD",|Sales Rank|: etc
>
I know how to get to the first level by using "set x to |Details| of
>
". What I don't know is how to get info out of the subrecord starting
>
with "{{". Thanks for any help.
It's a complicated structure, but not as bad as it looks. :-)
1. The SOAP result is a record.
2. The value of the record's field |Details| is a *list*.
3. This list contains one or more records:
{|Details|:{subrecord1, subrecord2, ... etc}}
4. If the list contains more than one record, they *probably* all have
similar fields.
The safest approach - both for a newbie and, in general, when dealing
with a 'record' returned by an application - is to mark each stage with a
variable:
set SOAPrecord to [the result returned by SOAP]
--> {|Details|:{{|Catalog|:"DVD", |Sales Rank|:"etc"}, {|Catalog|:"CD",
|Sales Rank|:"etc"}}}
set theDetails to |Details| of SOAPrecord
--> This is the list of records
set firstDetails to item 1 of theDetails
--> This is the first (or only) record in the list
set firstCatalog to |Catalog| of firstDetails
set firstSalesRank to |Sales Rank| of firstDetails
-- etc
If the SOAP record is a pure AppleScript structure that doesn't require
SOAP to read it, you can use long expressions like:
set firstSalesRank to |Sales Rank| of item 1 of |Details| of SOAPrecord
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.