• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: de-serialize plist string data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: de-serialize plist string data


  • Subject: Re: de-serialize plist string data
  • From: Shane Stanley <email@hidden>
  • Date: Mon, 31 Oct 2016 17:44:31 +1100

On 31 Oct. 2016, at 5:25 pm, Takaaki Naganoya <email@hidden> wrote:

set aList to {{theName:"Sound Track", numberOfTimes:1721}, {theName:"Rock", numberOfTimes:942}}

--listed record to XML stype plist string (Serialize)
set anArray to current application's NSArray's arrayWithObject:aList
set pListData to current application's NSPropertyListSerialization's dataFromPropertyList:anArray |format|:(current application's NSPropertyListXMLFormat_v1_0) errorDescription:(missing value)

You are using a deprecated method there -- better to use this:

set aList to {{theName:"Sound Track", numberOfTimes:1721}, {theName:"Rock", numberOfTimes:942}}

--listed record to XML stype plist string (Serialize)
set pListData to current application's NSPropertyListSerialization's dataWithPropertyList:aList |format|:(current application's NSPropertyListXMLFormat_v1_0) options:0 |error|:(missing value)
set bStr to (current application's NSString's alloc()'s initWithData:pListData encoding:(current application's NSUTF8StringEncoding)) as string


--De-serialize???
set deStr to current application's NSString's stringWithString:bStr
set aDic to current application's NSPropertyListSerialization's propertyListFromData:deStr mutabilityOption:(current application's NSPropertyListMutableContainersAndLeaves) |format|:(missing value) errorDescription:(missing value) ---[__NSCFString bytes]: unrecognized selector sent to instance 0x7fe52d36aab0 error -10000

You need to pass data, and you should use the newer method:

--De-serialize???
set deStr to current application's NSString's stringWithString:bStr
set theData to deStr's dataUsingEncoding:(current application's NSUTF8StringEncoding)
set aList to current application's NSPropertyListSerialization's propertyListWithData:theData options:(current application's NSPropertyListMutableContainersAndLeaves) |format|:(missing value) |error|:(missing value)
-->  {{theName:"Sound Track", numberOfTimes:1721}, {theName:"Rock", numberOfTimes:942}}--Goal (Success)


-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: de-serialize plist string data
      • From: Takaaki Naganoya <email@hidden>
References: 
 >de-serialize plist string data (From: Takaaki Naganoya <email@hidden>)

  • Prev by Date: de-serialize plist string data
  • Next by Date: Re: de-serialize plist string data
  • Previous by thread: de-serialize plist string data
  • Next by thread: Re: de-serialize plist string data
  • Index(es):
    • Date
    • Thread