ラベル Extension の投稿を表示しています。 すべての投稿を表示
ラベル Extension の投稿を表示しています。 すべての投稿を表示

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"

2019年1月18日金曜日

A JSON Decoding Extension for App Inventor (1)

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

[This Extension and  its doc are available. Please see the bottom of this article.]

JSON format is commonly used when receiving data from Web services, etc. With App Inventor, JsonTextDecode in the web block can convert JSON to list structures. Then, the conversion result can be manipulated by the selectItem and lookUpInPairs of the list block. However, as Evan W Patton (MIT) pointed out in the paper [1], these list processes are generally very complicated. And he also suggested a more readable and compact Extension block to alleviate this. 

I independently developed an Extension for JSON decode based on his new block idea. This Extension might be intuitive and easy to understand because it can hierarchically acquire necessary information with the tag names (properties) without using complicated operations on nested lists. The outline is shown in the figure below. (please enlarge and see the figure.)




This Extension takes two arguments. One is JSON data that was converted into list structure. The other is a search instruction list for hierarchically specifying the value of a specific tag (property). In this example, JSON text holds the values ​​of four kinds of sensors as "healthData". In the above figure, the name of the third sensor is specified. Note that in the query list, a number such as "3" indicates the element index of the JSON array structure.

Query List : John, healthData, 3, sensor
Result : Systolic pressure

JSON data used here is a modified version of the health data published in the following document [2]. The following figure shows the part of listing up all four sensors and their values ​​using this Extension. I think that it is written concisely. Operations for complicated list processing are not appeared here.


Collecting values of the four sensors



An example of running this application is shown below. For details, please see the files shown below.


Result of the test program on Android


Within this Extension, the list structure is iteratively processed using the function of YailList [3]. I think that YailList makes somewhat relaxation of complicated data type conversion (casting)  in JAVA. This Extension is still in beta. Although some of the JSON structures have been tested, all the structures are not covered, so bugs may be included. However, it is shown below for your reference. It was tested with Nexus 6 (Android 7.1.1). This extension was created using AppyBuilder Code Editor [4].

References

[1] JSON Interoperability in MIT App Inventor
https://2018.splashcon.org/event/blocks-2018-papers-json-interoperability-in-mit-app-inventor
[2] http://georgepavlides.info/ehealth-made-simple/
[3] http://3nportal.com/AIBridge/API/com/google/appinventor/components/runtime/util/YailList.html

[4] AppyBuilder Code Editor
http://Editor.AppyBuilder.com