On 2 Aug 2012, at 1:43 AM, Hassan Alnatour <[email protected]> wrote:
> i want to Generate json like this one :
> 
> {
>  "Result":"OK",
>  "Records":[
>   {"PersonId":1,"Name":"Benjamin 
> Button","Age":17,"RecordDate":"\/Date(1320259705710)\/"},
>   {"PersonId":2,"Name":"Douglas 
> Adams","Age":42,"RecordDate":"\/Date(1320259705710)\/"},
>   {"PersonId":3,"Name":"Isaac 
> Asimov","Age":26,"RecordDate":"\/Date(1320259705710)\/"},
>   {"PersonId":4,"Name":"Thomas 
> More","Age":65,"RecordDate":"\/Date(1320259705710)\/"}
>  ]
> }
> 
> so i did this :
> 
> def person():
>     
>     data = db().select(db.Person.ALL)
>     
>     mylist = {}
>     
>     mylist['Result'] = 'OK'
>     for i in data:
>      i.name = {'name':i.name,'age':i.age}
>      mylist['Records'].append(i.name)
>     return mylist
> 
> 
> then i open person.json , but i keep getting the order like this : 
> 
> 
> {"Records": [{"age": "222", "name": "hassan"}, {"age": "23", "name": 
> "mazen"}], "Result": "OK"}
> 
> but i want the 'Result' : 'ok'  to be at the beginning , what can i do ?
> 

Python dictionaries (and I assume JavaScript objects as well) are unordered. 
Why do you care?

-- 



Reply via email to