Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Sep 2006
    Posts
    9

    Question Order of json.decode ugly?

    Why does this...

    Code:
    local obj = json.decode( "{\"foo1\":\"foo1\", \"foo2\":\"foo2\", \"foo3\":\"foo3\", \"foo4\":\"foo4\", \"foo5\":\"foo5\", \"foo6\":\"foo6\"}" )
    for i,v in pairs(obj) do
       menu:addItem({ text = v })
    end
    ...result in a menu with this order: foo3, foo6, foo2, foo1, foo5, foo4
    instead of: foo1, foo2, foo3, foo4, foo5, foo6

    Any ideas?

  2. #2
    Senior Software Engineer - Logitech/Slim Devices
    Join Date
    Apr 2005
    Location
    Ipswich, UK
    Posts
    1,394
    lua tables with key, value pairs are unordered. You should use an array if order is important.

    Richard

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •