• 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: Json
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Json


  • Subject: Re: Json
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 17 Feb 2015 10:29:28 +1100

On 17 Feb 2015, at 12:44 am, Jörgen Stahle <email@hidden> wrote:

All slashes in text content will be escaped

Of course I can have a simple search & replace handle to take care if that – but can I instead tweak the Cocoa-related parts of the JSON export handler?

No, there is no such option. As far as I can see, escaping of slashes is optional. The only thing I can find are suggestions that some real-world implementations require it. All I can suggest is building in the search and replace, like this:

use framework "Foundation"

on convertASToJSON:someASThing saveTo:posixPath
--convert to JSON data
set {theData, theError} to current application's NSJSONSerialization's dataWithJSONObject:someASThing options:(current application's NSJSONWritingPrettyPrinted) |error|:(reference)
if theData is missing value then error (theError's localizedDescription() as text) number -10000
-- convert data to a UTF8 string
set someString to current application's NSString's alloc()'s initWithData:theData encoding:(current application's NSUTF8StringEncoding)
-- remove escaping from slashes
set someString to someString's stringByReplacingOccurrencesOfString:"\\/" withString:"/"
if posixPath is missing value then -- return string
return someString as text
else
-- write to file
someString's writeToFile:posixPath atomically:true encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)
return result as boolean -- returns false if save failed
end if
end convertASToJSON:saveTo:


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

 _______________________________________________
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: Json
      • From: Shane Stanley <email@hidden>
References: 
 >Json (From: Jörgen Stahle <email@hidden>)

  • Prev by Date: Script for Kindle Cloud Reader
  • Next by Date: Re: Applescript Studio?
  • Previous by thread: Json
  • Next by thread: Re: Json
  • Index(es):
    • Date
    • Thread