Finding data in JSON file


Asley Cruz

Hi David,

I have a JSON file, with some data like below sample.

How can I load the text of "texto" if "libro" = Juan (or "libro" = Pedro, or "libro" = Lucas)?

I want to show the data in a Table control.

Many thanks in advance.


AsleyCruz.com

Graphic & Web Designer


My app: AC Biblia

My game: AC Trivlia


decsoft

Hola Asley,

Maybe some further details can be needed. Supose we want to made a "filter" in the client side, and, the next code is placed inside the "Done" event of an "HttpClient" control, which serve the JSON to us, that is, the "HttpClient" response is the JSON that you shown as a sample.

As you can see, what we do is to initialize the "data" property of a "Table" control. Then we iterate over the "HttpClient" response, in other words, we iterate the JSON registries. As you can see, it's easy to find if the "libro" property of the iterated record / registry is one of the books that we want to show in the "Table" control, and, if so, we add that record / registry to the "date" property of the "Table" control, in order to be shown.

Note that, if the database is in the server side, the same operation can be done in the server side, that is, we ask to the server for some "books name" records, using the appropriate URL, for example: "https://www.appserver.com/items?books=1,2,3" (supose this 1, 2, 3, are the IDs of the required "books" in the database) so the server can prepare the right JSON output, so we no need to perform the filter in the client side, even when, as you can see, it's also possible.

Don't hesitate to ask if you have any further question around this, Asley.



Asley Cruz

Hi David,
Many thanks, it works great!

One more question... Using the same JSON data,
How can I delete the object (and all JSON data) with id value "2"?

Thanks for your time.
AsleyCruz.com

Graphic & Web Designer


My app: AC Biblia

My game: AC Trivlia


decsoft

Hello Asley,

Yes; it's possible to filter / delete records from the JSON source, for example:

Note, however, that we modify the original JSON source variable, so, we cannot get the deleted record back. But please, go ahead if you have any further question!



Asley Cruz

Thanks David, it works too but when I delete any JSON object, the remaining JSON data has a "double comma"
and unable to use this JSON data on a table because of the double comma.

How can I replace the double ",," comma with a single "," comma?
See below image with deleted JSON object, working on Android.

EDIT: I think that with a Agenda sample (in AB2) will be enough.


AsleyCruz.com

Graphic & Web Designer


My app: AC Biblia

My game: AC Trivlia


decsoft

Hola Asley,

Nope. If we have problems with the array deletion... we must prepare a different array, that is, modify the code to something like the below:

That is, what we do above is to prepare a new Array variable ("output") with all the "source" array items, except the items with "ID=2". So you can use then the "output" Array instead of the "source" one.



Asley Cruz

I did some changes and works great!

Thanks, David.


AsleyCruz.com

Graphic & Web Designer


My app: AC Biblia

My game: AC Trivlia


decsoft

No problem, Asley! Don't hesitate to post here or in other thread if you have any further questions.


Everybody can read the DecSoft support forum for learning purposes, however only DecSoft customers can post new threads. Purchase one or more licenses of some DecSoft products in order to give this and other benefits.

This website uses some useful cookies to store your preferences.

I agree. Hide this note. Give me more information.