本文介绍了使用jQuery从JSON字符串中的键中删除引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将此视为我的json字符串,
Consider this as my json string,
{"Table" : [{"userid" : "11","name" : "KumarP","designation" : "Business Head",
"phone" : "9789234793","email" : "[email protected]","role" : "Admin",
"empId" : "EI003","reportingto" : "KumarP"}]}
我想要这样的字符串,
{Table:[{ userid: "11", name: "KumarP", designation: "Business Head",
phone: "9789234793", email:"[email protected]", role : "Admin",
empId : "EI003",reportingto : "KumarP"}]}
我这样做是为了与jlinq一起使用.
I am doing so to use it with jlinq..
推荐答案
使用正则表达式:
var a='{"Table" : [{"userid" : "11","name" : "KumarP","designation" : "Business Head","phone" : "9789234793","email" : "[email protected]","role" : "Admin", "empId" : "EI003","reportingto" : "KumarP"}]}';
a=a.replace(/"(\w+)"\s*:/g, '$1:');
alert(a);
该字符串将成为您的第二个代码块:
The string will become as your second codeblock:
{Table: [{userid: "11",name: "KumarP",designation: "Business Head",phone: "9789234793",email: "[email protected]",role: "Admin", empId: "EI003",reportingto: "KumarP"}]}
但是如果标签是保留字,那不会引起问题吗?
But won't that cause a problem if the label was a reserved word?
这篇关于使用jQuery从JSON字符串中的键中删除引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!