JSON字符串分配不起作用

时间:2014-09-20 07:29:38

标签: javascript jquery json

我的代码有什么问题?我传递给这个函数一个JSON字符串,但赋值结束为空。我可以在函数参数中看到FireBug中的字符串,所以我知道它到达函数,但它不会使它超过赋值(在赋值中是“未定义”)。我想从字符串中拉出wty_upgrade数组。我正在使用我收到in this question帮助的一些代码。感谢

JSON字符串(正如我在FireBug中看到的那样:

{"wty_upgrade":[
    {"wty":"Upgrade from 3 to 5 years", "mth":24, "pig":3000}, 
    {"wty":"Upgrade from 3 to 10 years", "mth":84, "pig":8000}
]}

功能调用:

LoadWtyUpgPlans('3', JSON)

function LoadWtyUpgPlans(StdWty, UpgWty) {
    var WtyRow = '';
    var WtyUpgrades = UpgWty.wty_upgrade;    <--- here the assignment is blank/undefined
    STUFF HERE...
};

1 个答案:

答案 0 :(得分:0)

you can use as a this example may be useful fir you,
var jsn = '{"wty_upgrade":[
{"wty":"Upgrade from 3 to 5 years", "mth":24, "pig":3000}, 
{"wty":"Upgrade from 3 to 10 years", "mth":84, "pig":8000}]}';


 //OR you can parse then use
jsonres = JSON.parse(jsn);