我有一个像这样的字符串
{'Salary':'Basic_Salary - ( ESI * .5 ) - Employee_PF + Bonus','Gross_Salary':'( Salary - Tax )','Employee_PF': ''}
如果我有另一个字符串'Salary':'',
我想替换Salary并获得结果
{'Salary':'Basic_Salary - ( ESI * .5 ) - Employee_PF + Bonus','Gross_Salary':'( Salary - Tax )','Employee_PF': ''}
我可以轻松检查'Salary'
。我坚持的是,如何在''
'Salary':
中的字符串
答案 0 :(得分:1)
您基本上使用JSON对象作为字符串,在这种情况下,您可以将此字符串解码为JavaScript对象,然后将属性修改为任何其他对象
var obj = jQuery.parseJSON({'Salary':'Basic_Salary - ( ESI * .5 ) - Employee_PF + Bonus','Gross_Salary':'( Salary - Tax )','Employee_PF': ''});
然后:
obj.Salary = "Whatever you like";
然后你总是可以用
将它转换回字符串JSON.stringify
答案 1 :(得分:1)
var str = "{'Salary':'Basic_Salary - ( ESI * .5 ) - Employee_PF + Bonus','Gross_Salary':'( Salary - Tax )','Employee_PF': ''}";
var obj = JSON.parse(str);
obj.Salary = '';
str = JSON.stringify(obj);