List of Json structures?

I apologize for the topic, which has been widely discussed, but I'm missing some trivial detail.

The structure below was extracted from a list of telephone numbers, which I expected to come in a classic JSON format ( encapsulated between "{}'s ) but it seems rather like a list of several JSONs.

What would be the simplest/efficient approach to a large amount of data, encapsulate it and then create a single dictionary, or a list of "mini-dictionaries"?

Anyway, I can't see how to implement any of the options, could you help?

{ "user":"abcd", "mobile":"123456"},
{ "user":"bcde", "mobile":"234567"},
{ "user":"cdef", "mobile":"345678"},
....
{ "user":"efgh", "mobile":"456789"}

Add a [ at the start of the 'json' and an ] at the conclusion.

1 Like

You could do something like this:

1 Like

Thank you for the kind support, the above blocs worked like a charm.

Just to give some feedback ( and to provide additional info for those who are not fammiliar with these stuffs, like me ), with this approach it is possible to use the same structure to get back the user name from the telephone number, just replacing the "user" key with the "mobile" key.

Hello,

To avoid opening another topic, I would like to ask if I can have some more help on this thread.

If I wanted to insert the following list of names extracted from the above structure ( copied below ) into a Picklist, which dictionary/list blocks should I use to assemble a structure like...?

abcd,
bcde,
cdef,
efgh

[
{ "user":"abcd", "mobile":"123456"},
{ "user":"bcde", "mobile":"234567"},
{ "user":"cdef", "mobile":"345678"},
{ "user":"efgh", "mobile":"456789"}
]

Using the list map block would probably be the best way to do this (although there are a number of ways):

This assumes you've previously parsed the data into the parsedJson variable using the Web's JsonTextDecodeWithDictionaries block.

Hi,
I thought that could have some "inline" approach, such as this one, maybe?

https://community.appinventor.mit.edu/uploads/default/original/3X/d/f/df5bb78a7bc168fa201e632bb5356faa400367b0.png

I'll try both anyway...thanks.

You can inline any value block by right clicking on it and selecting "Inline Inputs". You can also collapse them either by the menu or double-clicking.

1 Like

Hi,

I'm trying to make the above blocks to work into the actual application (the yours, not mine), which unfortunatelly gave the follwing error:

Bad list argument to map
The second argument to map is not a list.
The second argument is "name1X surnemeX"

...whose data names/surnames contains spaces inbetween.

So the actual data is something like:

{ "user":"nameA surnameA", "mobile":"123456"},
{ "user":"nameB surnameB", "mobile":"234567"},
{ "user":"nameC surnameC", "mobile":"345678"},
....
{ "user":"nameX surnameX", "mobile":"456789"}

Do you think the error could be related to the space between name/surname, or due to the "" enclosing them ?

( please note that reported error contains the full name enclosed by "" )

Thank you again for the prompt reply.

(Canned Reply: ABG- Export & Upload .aia)
Export your .aia file and upload it here.
export_and_upload_aia

Hi @ABG ,

The code would not work anywhere else than here, because right in the first screen, a login authentication is required, whose database is located into a local network, at least for whle during development stage.

Is there another option, such as e.g trying to export the current screen and post here ?

(Canned Reply: ABG - Download those blocks and post them here)

Please download and post each of those event block(s)/procedures here ...
P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See Download Block Images for a demo.

Hi,

Please find attached.

The reported issue is at the event handler:
"When ListPicker_SelectUser.AfterPicking"
( located at the left-botton side of the picture )

The variable global UserList contains a Json structure formatted as:

[{ "user":"nameA surnameA", "mobile":"123456"},
{ "user":"nameB surnameB", "mobile":"234567"},
{ "user":"nameC surnameC", "mobile":"345678"},
....
{ "user":"nameX surnameX", "mobile":"456789"}]

The variable intended to contain the expected list ( nameA surnameA, nameB surnameB, ... ) is called listUsers

Thanks all you,

a simple approach

Hi

@Ria_Das ,
The issue is not selecting a specific item, but rather to extract the whole user list

@ABG ,
A complementary information, what is working and what isnt:
I mean, I can select the user from the listPicker ( code not at final shape ) but cannot list all users from the list.

But you can save all users in a global list directly from the json response as shown above. Can't undestand what you are trying to do

1 Like

Your NOK section is trying to extract a list from a single piece of text (a Name) from a single dictionary selected by SelectionIndex from your list of dictionaries.

If you want a list of names, try the walk path dictionary block on the JSON Decode With Dictionaries output, with path

  • walk at all levels
  • "name"
1 Like

@ Ria_Das Ohh sorry, I missed it.
Thanks, I'll have a try.

Just to give a feedback, now everything is working fine based on inputs of all yours, thanks once again; I didn't think it would be resolved so quickly, nice comunity.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.