-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

動的プロパティへのアクセスには角かっこを使用できます。

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