I want to create a data structure that will be parse as a JSON object. The out put must look like this and this should be a dynamic data structure.
{"data": [{"type": "locale", "lat": -34.43778387240597, "lon": 150.04799169921876},
{"type": "poi", "lat": -34.96615974838191, "lon": 149.89967626953126},
{"type": "locale", "lat": -34.72271328279892, "lon": 150.46547216796876},
{"type": "poi", "lat": -34.67303411621243, "lon": 149.96559423828126}]}
I'm struggling in the middle of implementing this data structure so expecting some good ideas.
Thanks
As response to the comment on Mathiasdm answer: You mean how to create dictionary with a list of dictionaries? That can be done like this:
dict = {}
dict["data"] = []
dict["data"].append({'type': 'poi', 'lat': 123})
dict["data"].append({'type': 'locale', 'lat': 321})
And so on.
But if this was really the problem, i would suggest to read the reference for lists and dictionaries again: http://docs.python.org/tutorial/datastructures.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With