Hi there, I need your help to parse a json string to charge on a Listview.
Here is string
[{"Art":"SOMEARTICLE","Nr":"3,00","Qnt":"12,00","Prz":"2,90","Tot":"36,19"}]
I should to pick every detail from this string and charge them on LV in this format
Thanks Timai, It could be good but there are many Art on list, so I think it would be better to put the result on the same line like this
Art Some art Nr 2.00 Qnt: 12.00 Prz: 23.00
and so on
Art Some art Nr 2.00 Qnt: 12.00 Prz: 23.00
Art Someart2 Nr 3.00 Qnt: 9.00 Prz: 11.00
Art Someart3 Nr 4.00 Qnt: 5.00 Prz: 6.00
Art Some art Nr 7.00 Qnt: 7.00 Prz: 9.00
I answered Tamai above, sadly I don't have an emulator to produce a screenshot, but I placed the output just how each row of the listview should be. I hope it is clear
Art Some art Nr 2.00 Qnt: 12.00 Prz: 23.00
Art Someart2 Nr 3.00 Qnt: 9.00 Prz: 11.00
Art Someart3 Nr 4.00 Qnt: 5.00 Prz: 6.00
Art Some art Nr 7.00 Qnt: 7.00 Prz: 9.00
Generally some data with quantity differences.
Imagine having to fill a shopping list, you could find bread, milk, beer and other things, so as to have the item with the relative quantity and price in the same line.
Is that your whole Json? I don't think so...so show all Json or more than just one record. Just show Json with more articles. Tim will need it for testing.
It was definitely a demanding and long enough job and I thank you for that. The solution works and returns the data in the form I expected, but apart from the solution, which is certainly a very important help, I wanted to ask where it would be possible to find some tutorials for managing json strings, which from what I learned in this weeks, can have different shapes and structures. I really like MIT App and since I use databases a lot and the query results come in json form, I would like to learn how to handle strings and how to get the data I need.
Thanks again.
There's one more thing I wanted to ask you: as you can see yourself, the setting of the data in each row, follows the order Art - Col - Prz - Qnt but I don't understand why since the Json string has the order "Art - Col - Qnt - Prz - Total"
Is there any way to manipulate this order? You didn't specify a specific key, but I see you iterated through the string values using each key in the list. I don't understand why the original order is broken down.
A good place to start is to read the AI2 documentation on Dictionaries and Lists (they are occasionally interchangeable, and json strings often contain list brackets (json arrays). Then you have the world wide web and google at your disposal for other learning resources on json.
When converting a json string to a dictionary in AI2 you will often find that keys (and their values attached) are returned in a different order, and again, often in alpha-numeric order. If you want to output in a particular order then you will need to do some more work to select each key in your preferred order to return the values.