I have json object of which i want to print its key/value pair combination. but my object is nested one. so i want to loop through each object and display its key/value pair.
Fiddle : http://jsfiddle.net/ydzsaot5/
Code:
var html='';
var contextObj = {"CategoryID":"1","BillerID":"23","BillerName":"MERCS","RequestType":"QuickPay","AccountNo":"1234567890","Authenticator":"{\"EmailAddress\":\"dfgsdfgsdfg\",\"MobileNumber\":\"65-4576573\",\"ID\":\"4572-4756876-8\"}","Token":"3C639AE65"};
html = getKeyValueJson(contextObj, html);
$('div').html(html);
function getKeyValueJson(obj, html) {
$.each(obj, function (key, value) {
if (value == null) {
return
}
if (typeof value == 'object') {
getKeyValueJson(value, html);
}
else {
html += '<label>' + key + '</label> :- <label>' + value + '</label><br>';
}
});
return html;
}
I want to print in this way :
....
AccountNo :- 1234567890
EmailAddress :- dfgsdfgsdfg
MobileNumber :- 65-4576573
....
Token :- 3C639AE65