1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to write and read different JSON objects as BLOB in file using angular

Discussão em 'Angular' iniciado por simon thismyvoice, Novembro 3, 2024 às 13:02.

  1. In my Angular program, have a class called myObj and an array called myArrayObj, that contains many instances of myObj.

    I am currently storing it into Blob and write into file, as shown below.

    const blob = new Blob([JSON.stringify([myArrayObj])], { type: 'application/json' });
    saveAs(blob, `${myFileName}.json`);


    To retrieve content from file, I have another set of codes.

    const fileReader = new FileReader();
    fileReader.onload = (e) => {
    const content = e.target?.result;
    if (typeof content === 'string') {
    const myArrayObj = JSON.parse(content);
    }


    My problem is that I want to save a single setting object (mySettingObject) into the file, before this array. How do I do that? How do I retrieve the setting object and array later?

    Continue reading...

Compartilhe esta Página