使用已解析的JSON设置变量

时间:2014-08-19 07:56:02

标签: javascript

我有一个解析的JSON,看起来像这样

{
    "pageName":"dsfdsf:sdfdsf:home",
    "prop1":"dsf:dsf","prop46":"OD",
    "prop5":"/content/",
    "prop24":"A Taste Of Home",
    "prop6":"1c4074ca-89bf-4d9f-8bd2-a5dc5f3ecf74",
    "prop3":"Home",
    "prop70":"dsf",
    "prop4":"dsf",
    "prop71":"desktop",
    "prop10":["dsfdsf"],
    "prop11":["sdfdsf"],
    "channel":"dsf"
} 

我可以从中提取密钥和值。我想在我的脚本标记中将此映射设置为JS变量,如

<script type="text/javascript">
     s.channel ="dsf"  // i need the prefix to be s. always and the variable should be set as s.key=value;
</script>

当我做s.key=value时没有任何反应。我已经尝试将s定义为JS对象,但没有快乐。我想将这些值传递给Tracking服务器,因此变量名称必须为s

以下作品

if(key==="channel"){
s.channel = value // this works

s.key=value没有。

0 个答案:

没有答案