Javascript {} is a map/hash table, not a list.  It doesn't have an
"order".

If you want the tag, tagname tuples in tag order, you have to put them
in tag order yourself.

Try "for tag, tagname in sorted(tags.itertems()):"

Note that "sorted(tags.iteritems())" sorts the keys in string order,
not numeric order, because the tags are strings, not numbers.  ("100"
< "2" even though 100 > 2.)

If you want numeric order, replace "sorted(tags.itertems())" with
something like "sorted([(int(k), v,) for (k,v,) in tags.itertems()])".



On Feb 6, 8:43 am, Dave <ddev...@gmail.com> wrote:
> Greetings, Hopefully this is something dumb I'm doing but simplejson
> is reording my lists/arrays. Has anyone seen this? Know how to fix?
>
> The scenario is I am placing tags and GLatLngs into db.ListProperties.
> However I've noticed that when written into the table the list is no
> longer in proper order which is a major problem for the GLatLngs....
>
> Specifically what appears to be happening and consistent is passing
> the following json string to simplejson:
>
> "tags": {
>         "0": "testtag 0",
>         "1": "testtag 1",
>         "2": "testtag 2",
>         "3": "testtag 3",
>         "4": "testtag 4"
>     }
>
> I get reordered data back such as:
>
> "tags": {"1":"testtag 1", "0":"testtag 0","3":"testtag 3","2":"testtag
> 2","4":"testtag 4"}
>
> This reordered pattern(1,0,3,2,4...) occurs for everything through
> simplejson. I've checked the input/output and removed simplejson to
> isolate it to simplejson doing the reordering.
>
> Code snippet below:
>
> if request.method == "POST":
>         data = request.POST['map']
>         json = simplejson.loads(data)
>         my_map = Map()
>         tags = json['tags']
>         for tag, tagname in tags.iteritems():
>                 my_map.tags.append(tagname)
>         my_map.save()
>
> Any help will be greatly appreciated. I'm looking at how to reorder
> data back, but ideally want to stop the json reordering.
>
> thx,
>
> Dave
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to