Totally new to Zig (or C etc)
I'm trying to parse some JSON from webUI via this example:
https://zig.guide/master/standard-library/json
I believe the error has to do with the !void union result
Removing the try and the union (the "guts"), removes the error for the main function but I can't connect the compiler errors with that.
Bind the webUI event receiver to my parser function (in main.zig)
_ = try win.binding("send_project_from_webui", proj.get_project_from_webui);
Event receiver function
pub fn send_project_from_webui(e: *webui.Event) void { const json = e.getString(); _ = json; }
Parser function
`pub fn get_project_from_webui(json: []const u8) !void {
const Setup = struct {
proj_name: []const u8,
proj_bpm: u16,
created: u32,
last_saved: u32
};
const allocator = std.heap.page_allocator;
const json_tree = try std.json.parseFromSlice(Setup, allocator, json, .{});
defer json_tree.deinit();
const json_val = try json_tree.value;
const proj_name = json_val.proj_name;
std.debug.print("\n\nPROJ_NAME{s}\n\n", .{proj_name});
}
`
The error...
Let's parse a JSON string into a struct type, using the streaming parser.