Hello Everyone,
I’ve implemented the functionality to receive a JSON response, count the number of objects, loop through them, and fetch a particular tag's value to add to a list for display. The code is working fine, but I was wondering if there’s a way to optimize it or if there’s an alternative method to achieve the same result more efficiently.
Is there a better or more efficient way to handle this process in MIT App Inventor? I would appreciate any suggestions or improvements.
Thanks in advance!
TIMAI2
September 16, 2024, 4:31pm
2
Show your responseContent
ABG
September 16, 2024, 4:52pm
3
I could not drag your blocks into my Blocks Workspace.
Could you post a small aia export?
{
"results": [
{
"objectId": "CETVWeA3Dz",
"createdAt": "2024-09-16T11:36:58.516Z",
"updatedAt": "2024-09-16T11:36:58.516Z",
"tag": "sabrina",
"value": "hello sourabh"
},
{
"objectId": "75M0BL3yG4",
"createdAt": "2024-09-16T13:07:50.290Z",
"updatedAt": "2024-09-16T13:07:50.290Z",
"tag": "ellie",
"value": "sabrina souru"
},
{
"objectId": "FFO2MoEjBn",
"createdAt": "2024-09-16T15:41:18.521Z",
"updatedAt": "2024-09-16T15:41:18.521Z",
"tag": "tag2",
"value": "tag3"
},
{
"objectId": "BDmlPXRbDv",
"createdAt": "2024-09-16T15:42:54.302Z",
"updatedAt": "2024-09-16T15:42:54.302Z",
"tag": "tag2",
"value": "hello"
},
{
"objectId": "CptgYFjP6S",
"createdAt": "2024-09-16T15:43:13.512Z",
"updatedAt": "2024-09-16T15:43:13.512Z",
"tag": "tag2",
"value": "Theek ha chalet"
},
{
"objectId": "0rSb77aEF7",
"createdAt": "2024-09-16T15:47:09.928Z",
"updatedAt": "2024-09-16T15:47:09.928Z",
"tag": "tag2",
"value": "hi"
},
{
"objectId": "BAbx5csYCH",
"createdAt": "2024-09-16T15:53:43.140Z",
"updatedAt": "2024-09-16T15:53:43.140Z",
"tag": "tag2",
"value": ""
},
{
"objectId": "CAV6z8tvNJ",
"createdAt": "2024-09-16T16:11:21.412Z",
"updatedAt": "2024-09-16T16:11:21.412Z",
"tag": "tag2",
"value": "okay"
}
]
}
ABG
September 16, 2024, 5:56pm
6
Here's my idea of improvement:
a global debug variable has the responseContent, in case the developer needs to see it
everything else is local variables, to avoid fights with the rest of the screen over global variable usage
save the results lookup, to avoid reparsing the JSON
use a For Each in List block for the iteration, to avoid indexing and selecting,
use direct dictionary lookup block on each item, because we're already there.
use a local variable for temporary Elements list accumulation.
reload the ListView only after finishing our input item loop.
chatnew2024_copy (1).aia (3.6 KB)
1 Like
Hi, thanks for the help it's working fine.
i'm just getting this error any idea about that?
-[__NSArrayM insertObject:atIndex:]: object cannot be nil. Irritants: ()
Note: You will not see another error reported for 5 seconds. *
TIMAI2
September 18, 2024, 7:35am
11
system
Closed
September 25, 2024, 7:35am
12
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.