1

I'm trying to filter a JSON url results using App Inventor 2, following sample codes from here1 and here2, but I still cannot get it done right. I only get one result at a time.

The JSON results are data in the form shown in the following figure:

{
"field1":"alphaNumeric1",
"field2":"aNumber1",
"field3":"DD/MM/YY",
"field4":"HH/MM/SS",
"field5":"https://",
"field6":"aText",
"field7":"aNumber2",
"field8":"alphaNumeric2",
"field9":"aNumber3",
"field10":"alphaNumeric3"
}

The JSON url is constantly updated, so are the results, but this is not a problem for now. I can get it read by a timer.

The problem is that from the above results, I need to parse "field2", "field5", "field6", in according labels in the app. So e.g., when I input a "aNumber1" to get searched in the JSON data, and have the result in a label.

Is it possible this JSON data search be done with App Inventor 2?

Anyone kind enough please answer with a sample blocks if possible. Thank you all in advance!

[EDIT 1]

No matter what I've tried, JSON could not get filtered right. Therefore I'm to filter the url results in XML.

The XML results are data in the form shown in the following figure:

<results>
<decision>
<alphaNumeric1>ABC1D</alphaNumeric1>
<aNumber1>ABCD</aNumber1>
<aDate>123</aDate>
<doc>HTTP</doc>
<aNumber2>1234</aNumber2>
<alphaNumeric2>TYPE</talphaNumeric2>
<aNumber3>12345</aNumber3>
<aNumber4>1234567</aNumber4>
<aText>SomeText</aText>
<aHour>00:00:00</aHour>
</decision>
.
.
.
<decision>
.
.
.
</decision>
.
.
.
</results>

I have tried to follow the example at here2, but I don't get it right. According to the XML output, what should I put in starTag and endTag, to get a parsing result if I'm searching for e.g. aNumber4 value (= 1234567) ?

Can someone respond with an answer?

[EDIT 2]

Well I'm trying to make some progress here following the example at here3.

The XML is being parsed with a runtime error "this is not a well formatted list of pairs".

Following is the blocks code I'm using:

enter image description here

Why is that so, since I'm following the example to the letter? Any clues anyone to solve this out?

Community
  • 1
  • 1
CodeBugging
  • 321
  • 12
  • 28
  • Learn [how to work with lists](http://www.imagnity.com/tutorials/app-inventor/list-blocks-on-app-inventor/) and [list of lists](http://www.appinventor.org/bookChapters/chapter19.pdf) (pdf) by [appinventor.org](http://www.appinventor.org/), then try something and if you still have issues, please provide a screenshot of your relevant blocks. – Taifun Dec 26 '15 at 21:02
  • Hi @Taifun. I appreciate your advice always, as you seem to be a master in app inventor, but I learn by practical examples better. Thats why I follow example code blocks as a guide. My question is, if it is possible to have a JSON url page, that is constantly populated by results, being searched for a specific value using app inventor. As this page has more than 1500+ comma unique values in its fields, how to make a searchable list on this issue? – CodeBugging Dec 26 '15 at 22:15
  • Convert the JSON into a list of lists and then use the `lookup in pairs` block to search for a specific value, [How does the lookup in pairs block work?](https://puravidaapps.com/snippets.php#2lookupinpairs) – Taifun Dec 27 '15 at 01:24

1 Answers1

1

well, your blocks look a little bit strange...

you have a complex list of lists, just use Do it to find out, how it looks like after each step of using lookup in pairs...

It helps to follow the already provided links:

In the example blocks below I looked for the first <decision> and displayed the value of tag aDate in Label1 like this

enter image description here

you might want to loop through the different <decision>s using a for each in list loop....

Taifun
  • 6,165
  • 17
  • 60
  • 188