键值对参数转换为Jquery json data参数
键值对:var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("a", "1"));
postData.Add(new KeyValuePair<string, string>("b", "2"));
postData.Add(new KeyValuePair<string, string>("c", "3"));
例如: var person = { jd_username: username, jd_password: password, jd_remeber: remeber };
等同于:‘ jd_username= ‘+ username+‘ &jd_password= ‘+password+‘ &jd_remeber= ‘+remeber
注意,如果参数有反斜杠则替换掉: var txtfeedback = $("#txtFeedback").val();
txtfeedback = txtfeedback.replace(/\n/g, " ")
*/
function jsonData(obj) {
var jsonStr = "({";
for (var o in obj) {
jsonStr += "\"" + o + "\":";
jsonStr += "\"" + obj[o] + "\"";
jsonStr += ",";
}
jsonStr = jsonStr.substring(0, jsonStr.length - 1);
jsonStr += "})";
return eval(jsonStr); //转换json格式
}
//json
result = "{result:‘ok‘,msg:‘审核通过‘}";
result = eval("[" + result + "]")[0];
result. Result=ok
result. Msg=通过
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。