在流星中将json解析为数组

时间:2015-03-09 11:28:38

标签: javascript json meteor

你好,我试图将这个json解析为数组

{"fields":[{"label":"Do you have a website?","field_type":"website","required":false,"field_options":{},"cid":"c1"},{"label":"Please enter your clearance number","field_type":"text","required":true,"field_options":{},"cid":"c6"},{"label":"Security personnel #82?","field_type":"radio","required":true,"field_options":{"options":[{"label":"Yes","checked":false},{"label":"No","checked":false}],"include_other_option":true},"cid":"c10"},{"label":"Medical history","field_type":"file","required":true,"field_options":{},"cid":"c14"},{"label":"Untitled","field_type":"text","required":true,"field_options":{"size":"small"},"cid":"c14"}]}

变量中的这个字符串,当我尝试添加到我的表单对象时,它是未定义的。

Meteor.call("formsUpsert",formulaire.id,{id:formulaire.id,fields:payload['fields'],name:formulaire.name,url:formulaire.url});

我也试过

Meteor.call("formsUpsert",formulaire.id,{id:formulaire.id,fields:payload.fields,name:formulaire.name,url:formulaire.url});

使用:

解决了它
console.log(payload);
    tab = payload;
    Meteor.call("formsUpsert",formulaire.id,{id:formulaire.id,fields:JSON.parse(tab).fields,name:formulaire.name,url:formulaire.url});

0 个答案:

没有答案