Page 1 of 1

How to sort a JSON object and afterwards map it to a select control?

Posted: Wed Feb 12, 2014 3:22 pm
by Chris A

How to sort by "distance" the following JSON object (produced by foursquare API) and afterwards map it to a select control?

{
"meta":{
"code":200
},
"response":{
"neighborhoods":[

Code: Select all

     ], 
     "venues":[ 
         { 
             "id":"3fd66200f964a5209fea1ee3", 
             "name":"Aquagrill", 
             "contact":{ 
                 "phone":"2122740505", 
                 "formattedPhone":"(212) 274-0505", 
                 "twitter":"aquagrillnyc" 
             }, 
             "location":{ 
                 "address":"210 Spring St", 
                 "crossStreet":"at 6th Ave.", 
                 "lat":40.72561895581218, 
                 "lng":-74.00389515789001, 
                 "distance":102, 
                 "postalCode":"10012", 
                 "cc":"US", 
                 "city":"New York", 
                 "state":"NY", 
                 "country":"United States" 
             }, 
             "categories":[ 
                 { 
                     "id":"4bf58dd8d48988d1ce941735", 
                     "name":"Seafood Restaurant", 
                     "pluralName":"Seafood Restaurants", 
                     "shortName":"Seafood", 
                     "icon":{ 
                         "prefix":"https:\/\/ss1.4sqi.net\/img\/categories_v2\/food\/seafood_", 
                         "suffix":".png" 
                     }, 
                     "primary":true 
                 } 
             ], 
             "verified":true, 
             "restricted":true, 
             "stats":{ 
                 "checkinsCount":6290, 
                 "usersCount":4597, 
                 "tipCount":99 
             }, 
             "url":"http:\/\/[url=http://www.aquagrill.com]www.aquagrill.com[/url]", 
             "menu":{ 
                 "type":"Menu", 
                 "label":"Menu", 
                 "anchor":"View Menu", 
                 "url":"https:\/\/foursquare.com\/v\/aquagrill-new-york-ny\/3fd66200f964a5209fea1ee3\/menu", 
                 "mobileUrl":"https:\/\/foursquare.com\/v\/3fd66200f964a5209fea1ee3\/device_menu" 
             }, 
             "specials":{ 
                 "count":0, 
                 "items":[ 

                 ] 
             }, 
             "hereNow":{ 
                 "count":0, 
                 "groups":[ 

                 ] 
             }, 
             "venuePage":{ 
                 "id":"68245436" 
             }, 
             "referralId":"v-1392218019" 
         }, 
         { 
             "id":"4a7ca51ff964a52012ed1fe3", 
             "name":"Physique 57", 
             "contact":{ 
                 "phone":"2124630570", 
                 "formattedPhone":"(212) 463-0570", 
                 "twitter":"physique57" 
             }, 
             "location":{ 
                 "address":"161 Ave of the Americas", 
                 "crossStreet":"at Spring St", 
                 "lat":40.72583480849319, 
                 "lng":-74.00399845123462, 
                 "distance":43, 
                 "postalCode":"10013", 
                 "cc":"US", 
                 "city":"New York", 
                 "state":"NY", 
                 "country":"United States" 
             }, 
             "categories":[ 
                 { 
                     "id":"4bf58dd8d48988d176941735", 
                     "name":"Gym", 
                     "pluralName":"Gyms", 
                     "shortName":"Gym", 
                     "icon":{ 
                         "prefix":"https:\/\/ss1.4sqi.net\/img\/categories_v2\/building\/gym_", 
                         "suffix":".png" 
                     }, 
                     "primary":true 
                 } 
             ], 
             "verified":true, 
             "restricted":true, 
             "stats":{ 
                 "checkinsCount":9974, 
                 "usersCount":1077, 
                 "tipCount":30 
             }, 
             "url":"http:\/\/[url=http://www.physique57.com]www.physique57.com[/url]", 
             "specials":{ 
                 "count":0, 
                 "items":[ 

                 ] 
             }, 
             "hereNow":{ 
                 "count":1, 
                 "groups":[ 
                     { 
                         "type":"others", 
                         "name":"Other people here", 
                         "count":1, 
                         "items":[ 

                         ] 
                     } 
                 ] 
             }, 
             "referralId":"v-1392218019" 
         } 
       ], 
     "confident":true 
 } 

}


How to sort a JSON object and afterwards map it to a select control?

Posted: Wed Feb 12, 2014 4:00 pm
by Kateryna Grynko

Hi Chris,

You would need to write a Compare function yourself. Find an example here please: https://learn.jquery.com/javascript-1...


How to sort a JSON object and afterwards map it to a select control?

Posted: Wed Feb 12, 2014 11:59 pm
by Chris A

Hi Katya,

that's the easy part... what I don't understand is where to plug that function so that I can still leverage your mapping system that I like very much.


How to sort a JSON object and afterwards map it to a select control?

Posted: Thu Feb 13, 2014 10:52 am
by Chris A

Never mind, by looking around I guess that can be achieved with the General Service and the Echo response.


How to sort a JSON object and afterwards map it to a select control?

Posted: Thu Feb 13, 2014 11:24 am
by Maryna Brodina

Hello! You would need to create compare function, this should help https://learn.jquery.com/javascript-1...