javascript - make JSON attributes keys links on the first level

前端 未结 2 1303
梦毁少年i
梦毁少年i 2021-01-27 05:45

I need to prettify some JSON to display within an HTML

 section.

The working javascript code I use is..

function transformJson(k,         


        
2条回答
  •  孤街浪徒
    2021-01-27 06:08

    Simply adding this after JSON.parse did the trick..

    var newObj = {};
    
    for(var attr in jsonObj){
        if( jsonObj[attr].constructor != Object && attr != 'href'){
            newObj[''+attr+''] = jsonObj[attr];
        }else{
            newObj[attr] = jsonObj[attr];
        }
    }
    

    (And then clearly JSON.stringify applied to newObj)

提交回复
热议问题