mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-17 16:28:06 +03:00
Ladybird: Add a helper to deserialize a JSON string to an NSDictionary
The steps here are a tad verbose, and will be needed several times in the Inspector window.
This commit is contained in:
parent
507dea5fdd
commit
33b006f157
Notes:
sideshowbarker
2024-07-17 22:09:47 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/33b006f157 Pull-request: https://github.com/SerenityOS/serenity/pull/21063 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/bugaevc
@ -19,6 +19,8 @@ namespace Ladybird {
|
||||
String ns_string_to_string(NSString*);
|
||||
NSString* string_to_ns_string(StringView);
|
||||
|
||||
NSDictionary* deserialize_json_to_dictionary(StringView);
|
||||
|
||||
Gfx::IntRect ns_rect_to_gfx_rect(NSRect);
|
||||
NSRect gfx_rect_to_ns_rect(Gfx::IntRect);
|
||||
|
||||
|
@ -20,6 +20,23 @@ NSString* string_to_ns_string(StringView string)
|
||||
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
NSDictionary* deserialize_json_to_dictionary(StringView json)
|
||||
{
|
||||
auto* ns_json = string_to_ns_string(json);
|
||||
auto* json_data = [ns_json dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
NSError* error = nil;
|
||||
NSDictionary* dictionary = [NSJSONSerialization JSONObjectWithData:json_data
|
||||
options:0
|
||||
error:&error];
|
||||
|
||||
if (!dictionary) {
|
||||
NSLog(@"Error deserializing DOM tree: %@", error);
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
Gfx::IntRect ns_rect_to_gfx_rect(NSRect rect)
|
||||
{
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user