mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:17:44 +00: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
2 changed files with 19 additions and 0 deletions
|
@ -19,6 +19,8 @@ namespace Ladybird {
|
||||||
String ns_string_to_string(NSString*);
|
String ns_string_to_string(NSString*);
|
||||||
NSString* string_to_ns_string(StringView);
|
NSString* string_to_ns_string(StringView);
|
||||||
|
|
||||||
|
NSDictionary* deserialize_json_to_dictionary(StringView);
|
||||||
|
|
||||||
Gfx::IntRect ns_rect_to_gfx_rect(NSRect);
|
Gfx::IntRect ns_rect_to_gfx_rect(NSRect);
|
||||||
NSRect gfx_rect_to_ns_rect(Gfx::IntRect);
|
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];
|
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)
|
Gfx::IntRect ns_rect_to_gfx_rect(NSRect rect)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue