Json response to dropdown elements

Hi, I’m finishing up this feature, and I got a json response from the server. I need to pluck the name and id of this array and wrap it into a dropdown menu.

I haven’t parsed any json before, if someone could point me in the right direction, I would be grateful.

What does this JSON look like? And where do you want to do this?

Are you trying to do this in the page (using JavaScript)? Or are you trying to create the select tag on the server based on the API reply, and then do something with that?

More details would help us help you…

Walter

ok it took me some trial and error and some luck.

The json wasn’t in a key/value pair, so I had to refer to the val, like val.id and val.name to get the correct values from the payload.

then I stuffed them into a dropdown menu

part of my code…

    } else if  ($("#blah").val() == 'ESI') {
          alert("ESI");
          $(".blah").show();


          $.ajax({
            type: "GET",
            url: '/lists/18',
            dataType: 'json',
            success: function(data) {
              var bin_ele = $('#blah');
              bin_ele.empty();

              $.each(data, function(key, val) {
                bin_ele.append($("<option></option>").attr("value", val.id).text(val.name));
              });

            }
          });

this populated a dropdown on the selection of the previous dropdown.