API Structures to Local Storage

API Structures to Local Storage

  

Hi everyone,

i want to ask something about how to move structures from consumed REST API to Local Storage (Mobile App)

Case:

So i have already consume REST API and i got the Structures from it. My question is how can i move (or fill) the API data to the local storage?


Thankyou.

REST API JSON Structure are complex data type (nested record/list), you need to either store whole JSON string or normalize into simple data structure then save it to Local Storage.

To save into local storage is simple, just use Create<entityname> or CreateOrUpdate<entityname>.

If you decide to store whole JSON string, you can Deserialize it back into structure using JSONDeserialize action.

Harlin Setiadarma wrote:

REST API JSON Structure are complex data type (nested record/list), you need to either store whole JSON string or normalize into simple data structure then save it to Local Storage.

To save into local storage is simple, just use Create<entityname> or CreateOrUpdate<entityname>.

If you decide to store whole JSON string, you can Deserialize it back into structure using JSONDeserialize action.

Hi, thank you for the reply

so, now my question is: how to normalize the structure and save it into local storage?

is it can be done just by assign it in a client action?

thankyou

Solution

No, JSON structure is very dynamic.

You should normalize it manually based on your JSON structure.

{

     "error_code": 0,

     "error_message": "Success",

     {

         "data1": "xxxx",

         "data2": "xxxx",

         "data3": "xxxx"

     }

}


you could save it into entity with these attributes: error_code, error_message, data1, data2, data3


However if your JSON structure like below (have array/list):

{

     "error_code": 0,

     "error_message": "Success",

     [ {

         "data1": "xxxx",

         "data2": "xxxx",

         "data3": "xxxx"

     },

     {

         "data1": "xxxx",

         "data2": "xxxx",

         "data3": "xxxx"

     } ]

}


You should save it to 2 different entities.


So, no generic action available for all json structure.

Your best bet is to save whole JSON string into entity, and then deserialize it when you need the info.

Solution

Harlin Setiadarma wrote:

No, JSON structure is very dynamic.

You should normalize it manually based on your JSON structure.

{

     "error_code": 0,

     "error_message": "Success",

     {

         "data1": "xxxx",

         "data2": "xxxx",

         "data3": "xxxx"

     }

}


you could save it into entity with these attributes: error_code, error_message, data1, data2, data3


However if your JSON structure like below (have array/list):

{

     "error_code": 0,

     "error_message": "Success",

     [ {

         "data1": "xxxx",

         "data2": "xxxx",

         "data3": "xxxx"

     },

     {

         "data1": "xxxx",

         "data2": "xxxx",

         "data3": "xxxx"

     } ]

}


You should save it to 2 different entities.


So, no generic action available for all json structure.

Your best bet is to save whole JSON string into entity, and then deserialize it when you need the info.


thankyou for the answer