|
飞哥,请问我用助手运行JS方法时,此方法传入一个JSON值,可运行时为什么会报错?我哪里写错了?求助,谢谢
StringBuilder sb = new StringBuilder();
sb.Append("function getContentStr(data) {");
sb.Append(" let content = sortObj(Object.assign(data))");
sb.Append(" let keys = Object.keys(content).sort()");
sb.Append(" let newArr = []");
sb.Append(" for (let key of keys) {");
sb.Append(" let val = content[key]");
sb.Append(" if (typeof val == 'object') {");
sb.Append(" val = JSON.stringify(val)");
sb.Append(" }");
sb.Append(" newArr.push(`${key}=${val}`)");
sb.Append(" }");
sb.Append(" let contentStr = newArr.join('&')");
sb.Append(" contentStr += 'kosun.net'");
sb.Append(" return contentStr");
sb.Append("}");
sb.Append("");
sb.Append("function sortObj(obj) {");
sb.Append(" let sortKeys = Object.keys(obj).sort()");
sb.Append(" let newObj = {}");
sb.Append(" for (let key of sortKeys) {");
sb.Append(" let val = obj[key]");
sb.Append(" if (typeof val == 'object') {");
sb.Append(" if (Array.isArray(val)) {");
sb.Append(" newObj[key] = sortArray(val)");
sb.Append(" } else if (!Array.isArray(val) && Object.keys(val).length > 0) {");
sb.Append(" newObj[key] = sortObj(val)");
sb.Append(" } else {");
sb.Append(" newObj[key] = val");
sb.Append(" }");
sb.Append(" } else {");
sb.Append(" newObj[key] = val");
sb.Append(" }");
sb.Append(" }");
sb.Append(" return newObj");
sb.Append("}");
StringBuilder sb1 = new StringBuilder();
sb1.Append({\"act\":208,\"channel_name\":\"PC\",\"is_special_agent\":0,\"password\":\"123\",\"login_terminal\":1,\"user_name\":\"G28730\",\"verify_code\":\"5546\"}");
MessageBox.Show(HttpHelper.JavaScriptEval(sb.ToString(), "getContentStr(" + sb1.ToString() + ")"));
|
|