Oaks-view
Oaks-view

Reputation: 433

Retrieve json store keys in a predetermined order in kivy?

Im working on a program using kivy and python, and i will be saving some data to a json file like say 'items.json'. The thing is i intend to retrieve the data from the store and use them to form a list of buttons in my app. here is an example.

store = JsonStore('items.json')
store.put('infinix', name = 'infinix', category = 'gadgets')
store.put('wrist watch', name = 'wrist watch', category = 'outfits')
store.put('t-shirt', name = 't-shirt', category = 'outfits')

this works well. But my problem is in retrieving the data. i would like to get them in the same order i entered the data into the store. for example if i do

store.keys()

i would like it to return

['infinix', 'wrist watch', 't-shirt']

which is the same order i entered the data.

currently whenever i try to retrieve the data, the order is mixed up. is there a way to achieve what i need? Any help is greatly appreciated.

Upvotes: 0

Views: 252

Answers (1)

inclement
inclement

Reputation: 29450

The simplest option would seem to be just adding an extra storage key containing a list of your items in the correct order. You can then just check this first, and load them in that order.

Upvotes: 1

Related Questions