Announcement

Collapse
No announcement yet.

sort JSON?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    sort JSON?

    Is it possible using one of the available sort options to sort a json response?

    Example json:
    {"data":[{"name":"John","age":30,"car":null,"messages":[{"message1":"hello","message3":"out of order","message2":"goodbye"}]},{"name":"Allen","age":30,"car":null,"messages":[{"message1":"hello","message3":"out of order","message2":"goodbye"}]}]}

    I'd like to sort first on data[]:name
    and then on data[]:name:messages
    William Gilligan - Orange Marmalade, Inc.
    www.OrangeMarmaladeinc.com

    #2
    You can use miva_array_sort. You'll first have to decode the JSON data, then use miva_array_sort to define a custom sort callback function. Within that callback function you'll be able to sort the data based on name. You'll probably also have to call miva_array_sort for each user within the first miva_array_sort callback in order to sort the messages for that user as well.
    David Carver
    Miva, Inc. | Software Developer

    Comment


      #3
      In case you don't know, I published a sorting function that's very efficient, versatile, and easy to use (no callback needed). You can see it at http://themagicm.com/store/a-new-miv...-function.html. Ray Yates of PCINet wrote a version with a couple of improvements. I'm not sure if he's published it on a Web page, but I can send you a copy if necessary.
      Kent Multer
      Magic Metal Productions
      http://TheMagicM.com
      * Web developer/designer
      * E-commerce and Miva
      * Author, The Official Miva Web Scripting Book -- available on-line:
      http://www.amazon.com/exec/obidos/IS...icmetalproducA

      Comment


        #4
        Originally posted by Kent Multer View Post
        In case you don't know, I published a sorting function that's very efficient, versatile, and easy to use (no callback needed). You can see it at http://themagicm.com/store/a-new-miv...-function.html. Ray Yates of PCINet wrote a version with a couple of improvements. I'm not sure if he's published it on a Web page, but I can send you a copy if necessary.
        Thanks Kent,
        I did not know. I will check it out!

        Bill
        William Gilligan - Orange Marmalade, Inc.
        www.OrangeMarmaladeinc.com

        Comment

        Working...
        X