You are not logged in.
I have a question regarding extracting bytes from data/buffer in other words.
I like to set a object to some NSData and extract its bytes in integer.
Is this the method to use: https://developer.apple.com/documentati … guage=objc
I doing some research on html 2 JSON. So I made this example.
Showing to extract JSON from HTML.
Applescript:
use framework "Foundation"
use scripting additions
(** [Objective-C]
* NSString * html = @"<html><head></head><body>{\"data\":{\"type\":\"success\",\"message\":\"Thanks for order with XYZ.\"}}</body></html>";
* NSData * data = [html dataUsingEncoding:NSUTF8StringEncoding];
* NSAttributedString * attributedString = [[NSAttributedString alloc] initWithHTML:data documentAttributes:nil];
* NSData * jsonData = [attributedString.string dataUsingEncoding:NSUTF8StringEncoding];
* NSDictionary * result = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
* NSLog(@"Output %@",result);
*)
set theHTML to "<html><head></head><body>{\"data\":{\"type\":\"success\",\"message\":\"Thanks for order with XYZ.\"}}</body></html>"
set theData to (current application's NSString's stringWithString:theHTML)'s dataUsingEncoding:(current application's NSUTF8StringEncoding)
set attributedString to current application's NSAttributedString's alloc()'s initWithHTML:theData documentAttributes:(missing value)
set jsonData to attributedString's |string|'s dataUsingEncoding:(current application's NSUTF8StringEncoding)
set {theResult, theError} to current application's NSJSONSerialization's JSONObjectWithData:jsonData options:0 |error|:(reference)
set theResult to theResult as record
its message of |data| of theResult
The purpose to study someone else art is not to add, its to make less more.
Offline