jquery - How to convert json containg different key value pairs to a list javascript? -


this question has answer here:

i have json string in format

var jsondata =    [{"label":"hass1(xxx_sem@hotmail.com)","value":"xxx_sem@hotmail.com"},{"label":"hass(sxx_sem@hotmail.com)","value":"sxx_sem@hotmail.com"},{"label":"sam(sx_sem@hotmail.com)","value":"sx_sem@hotmail.com"}] 

i need convert in format way

var obj = {"hass1(xxx_sem@hotmail.com)":"xxx_sem@hotmail.com",           "hass(sxx_sem@hotmail.com)","sxx_sem@hotmail.com"} 

how so?

i have implemented far like

function convertmejason(jsonme) {             var list = json.parse(jsonme);             list.object.foreach(function (obj) { /// getting error undefined function foreach                 emptyjson.add('"' + obj.label + '"', '"' + obj.value + '"');             })         } 

something this:

function convert(data) {     var obj = {};     (var = 0; i<data.length; i++) {         obj[data[i].label] = data[i].value;     }     return obj; } 

here jsfiddle.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -