-3
//Creating a 2-d Json array


var JSONObject = {
"name": "John Johnson",
    "street": "Oslo West 16",
    "age": 33,
    "phone": "555 1234567"
 };

var JSONObject1 = {
    "movie": "zindagi",
    "wedding": "yes"
};

var cookieval = {
    "akamai" + ':' + JSONObject,
    "sV" + ':' + JSONObject1
 }


$.cookie('test', cookieval); // creating a cookie with a Json value
readJson('test', 'sV');

function readJSON(name, param) {
   var cookievalue = $.cookie('test');
   var parJson = $.parseJSON(cookievalue);
   var strmovie = parJson.sV;


  //Should return me JSOn object of sV and this works but when i try the following it does not.
  var  strmovie = parJson+'.'+param;
  // Because param is a string and not Json, var strMovie returns an undefined value. 
  // How do i get the value of json dynamically
}
4

1 回答 1

2

You can use square brackets for dynamic property access:

var strmovie = parJson[param];
于 2013-06-28T17:20:30.280 回答