Re: Json
Re: Json
- Subject: Re: Json
- From: Emmanuel LEVY <email@hidden>
- Date: Tue, 17 Feb 2015 17:19:04 +0100
Just in case, I mention that we use Satimage's XMLLib osax to go from plists to json or reverse. Here are a few examples, where I use PlistNew to make AppleScript data into a plist.
PlistToJSON (PlistNew "blah")
-- "\"blah\""
PlistToJSON (PlistNew 3.14)
-- "3.14"
PlistToJSON (PlistNew {fast:true, complex:false})
-- "{\"fast\":true,\"complex\":false}"
PlistToJSON (PlistNew {1, 2, "c", "d"})
-- "[1,2,\"c\",\"d\"]"
PlistToJSON (PlistNew {somekey:"somevalue", anotherkey:3.14})
-- "{\"somekey\":\"somevalue\",\"anotherkey\":3.14}"
XMLLib is part of Smile's install but you can use it independently, I think.
Emmanuel
On Feb 16, 2015, at 2:44 PM, Jörgen Stahle wrote:
> Hi, all
>
> This question concerns code for an applescript library once published by Shane Stanley i Macscripter’s forums so it is mainly directed to him – but of course others ar also welcome to answer!
>
> The library in question, can among other things, be used to export JSON code from applescript.
>
> I want to use that very JSON export function. It works fine, but I have one issue about the JSON output: All slashes in text content will be escaped
>
> So for example an ftp uri will be written:
> ftp:\/\/ftp.host.se
>
> What i want is just:
> ftp://ftp.host.se
>
> 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? I guess that would make the function faster. I know almost nothing about Cocoa. So, can you help me?
>
> The handler I refer to is this:
>
>
> -- pass a string, list, record or number, and either a path to save the result to, or missing value to have it returned as text
> on convertASToJSON:someASThing saveTo:posixPath
> --convert to JSON data
> set {theData, theError} to current application's NSJSONSerialization's dataWithJSONObject:someASThing options:0 |error|:(reference)
> if theData is missing value then error (theError's localizedDescription() as text) number -10000
> if posixPath is missing value then -- return string
> -- convert data to a UTF8 string
> set someString to current application's NSString's alloc()'s initWithData:theData encoding:(current application's NSUTF8StringEncoding)
> return someString as text
> else
> -- write data to file
> theData's writeToFile:posixPath atomically:true
> return result as boolean -- returns false if save failed
> end if
> end convertASToJSON:saveTo:
>
> _______________________________________________
> 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
_______________________________________________
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: Jörgen Stahle <email@hidden>
References: | |
| >Json (From: Jörgen Stahle <email@hidden>) |