2019年1月19日土曜日

A JSON Decoding Extension for App Inventor (2)

[Dec.6, 2019] For your convenience, another example is shown below:
https://sparse-dense.blogspot.com/2019/12/another-example-using-json-decoding.html

In the previous article, I introduced a JSON Decode Extension to easily extract the necessary information from the JSON file received from a Web service. This time, in order to test this Extension, I created a simple book search application. There are many applications of this type, but the concern here is how easy it is to decode JSON files.


Results from the book search app
The created application is as shown above. It shows the search results of one English book and two Japanese books. Giving a few keywords, Google Book Search searches for books and returns the results in JSON text as shown below. In this example, I set to receive only one book out of hit books.


JSON text sent back from the web service (a part)
For example, in the first search, "Galois" and "Groups" were given as keywords. The resulting Json text is shown above. "title", "authors", "publishedDate", "thumbnail" and "description" are extracted and displayed from this data. The program is shown in the figure below. This is all of the source program. Therefore, it can be said that this is made quite compact.

Complete App Inventor source program of the book search

However, there is still room for improvement. For example, the current Extension receives the following list individually as a search instruction string.

query for title -> "items,volumeInfo,title"
query for authors -> "items,volumeInfo,authors"
query for publishedDate -> "items,volumeInfo,publishedDate"
query for thumbnail -> "items,volumeInfo,imageLinks,thumbnail"
query for description -> "items,volumeInfo,description"

This is a little inefficient. The values ​​of tags at the same hierarchical level should be collectively received as follows. In the near future, we plan to revise the extension so that we can respond to this. That way, you can make this application even easier.

query for several items -> "items,volumeInfo,[title,authors,publishedDate,description]"
query for thumbnail -> "items,volumeInfo,imageLinks,thumbnail"

2 件のコメント:

  1. hi

    i try your extension
    i would like to know if i can decode this kind of json format with it :
    {"blues":[{"id":"1","codeb":"","prenom":"je","nom":"test","piece":"v","datecreation":"","datesortie":"","dateretour":"","etat":"g"},{"id":"1","codeb":"","prenom":"je","nom":"test","piece":"v","datecreation":"","datesortie":"","dateretour":"","etat":"g"},{"id":"1","codeb":"","prenom":"je","nom":"test","piece":"v","datecreation":"","datesortie":"","dateretour":"","etat":"g"},{"id":"1","codeb":"","prenom":"je","nom":"test","piece":"p","datecreation":"","datesortie":"","dateretour":"","etat":"g"},{"id":"1","codeb":7000022,"prenom":"je","nom":"test","piece":"p","datecreation":"","datesortie":"","dateretour":"","etat":"g"},{"id":"1","codeb":"","prenom":"je","nom":"test","piece":"p","datecreation":"","datesortie":"","dateretour":"","etat":"g"},{"id":"1","codeb":"","prenom":"je","nom":"test","piece":"p","datecreation":"","datesortie":"","dateretour":"","etat":"g"}]}

    regards

    返信削除
    返信
    1. Sorry, I do not understand what you expect as a result of decoding. However, for example, if you want to get the value of the "codeb" tag of the fifth element under the "blues" tag in this json file, you can do something like the following figure.
      https://www.dropbox.com/s/2yh3asw86pjeebb/b.png?dl=0
      As a result, "7000022" will be obtained. I hope you find it useful.

      削除