Key value pairs using JSON

后端 未结 4 2116
一向
一向 2020-12-23 22:41

Is there a way to handle data structures using JSON object in a way of Key/ Value pairs?
If so can some one elaborate how to access associated value object from the key

4条回答
  •  甜味超标
    2020-12-23 23:17

    var object = {
        key1 : {
            name : 'xxxxxx',
            value : '100.0'
        },
        key2 : {
            name : 'yyyyyyy',
            value : '200.0'
        },
        key3 : {
            name : 'zzzzzz',
            value : '500.0'
        },
    }
    

    If thats how your object looks and you want to loop each name and value then I would try and do something like.

    $.each(object,function(key,innerjson){
        /*
            key would be key1,key2,key3
            innerjson would be the name and value **
        */
    
        //Alerts and logging of the variable.
        console.log(innerjson); //should show you the value    
        alert(innerjson.name); //Should say xxxxxx,yyyyyy,zzzzzzz
    });
    

提交回复
热议问题