js中正则匹配到无效数据,在其他语言中不会 财富值7

2016-04-03 05:04发布

//如下代码,我的目的是想匹配所有json 中的key 可是在第十二个的时候匹配 到无效的数据,在其他语言中就不会

function PaseJson(jsonObj) {

//先转成字符串 var jsonStr = JSON.stringify(jsonObj);  var i = 0;  jsonStr.match(/"(.*?)":/g).forEach(function(a) {     console.log("第:" + i + "个:" + a);     i++; });

}

原json
{

"ColumnMode": null, "Columns": ["id", "在线", "名称", "账号", "信用额度", "信用余额", "盘口", "分公司", "股东", "总代理", "代理", "添加日期", "状态"], "MsgStr": null, "MsgTypeId": 0, "MyPower": [12, 12, 13, 15], "PageInfo": {     "PageIndex": 1,     "PageSum": 0,     "ResultSum": 9,     "ShowNum": 20 }, "ResultNum": 9, "Rows": [     ["60", "False", "会员1[代理1]", "hy1", "200.0000", "200.0000", "A", "fgs1<br>0%", "gd1<br>20%", "zdl1<br>30%", "dl1<br>20%", "2016-03-19 17:19:13", "1"],     ["61", "False", "会员2[代理2]", "hy2", "100.0000", "100.0000", "A", "fgs2<br>20%", "gd2<br>10%", "zdl2<br>30%", "dl2<br>10%", "2016-03-19 17:20:14", "1"],     ["62", "False", "会员3[代理1]", "hy3", "100.0000", "100.0000", "A", "fgs1<br>0%", "gd1<br>20%", "zdl1<br>30%", "dl1<br>5%", "2016-03-19 17:20:57", "1"],     ["63", "False", "会员4[分公司1]", "hy4", "500.0000", "500.0000", "A", "fgs1<br>20%", "", "", "", "2016-03-19 17:22:55", "1"],     ["68", "False", "会员5[代理3]", "hy5", "1000.0000", "0.0000", "A", "fgs3<br>30%", "gd3<br>0%", "zdl3<br>30%", "dl3<br>20%", "2016-03-19 22:05:34", "1"],     ["69", "False", "会员6[分公司3]", "hy6", "1000.0000", "278.0000", "A", "fgs3<br>40%", "", "", "", "2016-03-21 13:59:56", "1"],     ["70", "False", "会员7[分公司3]", "hy7", "10000.0000", "10000.0000", "A", "fgs3<br>20%", "", "", "", "2016-03-23 13:43:02", "1"],     ["72", "False", "会员8[分公司4]", "hy8", "1000000.0000", "683171.0000", "A", "fgs4<br>40%", "", "", "", "2016-03-23 13:46:46", "1"],     ["76", "False", "hy9[代理4]", "hy9", "1000000.0000", "896718.0000", "A", "fgs4<br>30%", "gd4<br>10%", "zdl4<br>10%", "dl4<br>30%", "2016-03-24 16:20:13", "1"] ], "Succeed": false, "Supers": [], "Variable": null

}

1条回答
try2016 - 没有你的世界,毁了也无所谓。
1楼 · 2016-04-03 09:04.采纳回答

原因是你看到的json和JSON.stringify()后的结果不一致。
你的正则对原json没有问题,但是对stringify后就不对了,stringify后的字符串为:

{"ColumnMode":null,"Columns":["id","在线","名称","账号","信用额度","信用余额","盘口","分公司","股东","总代理","代理","添加日期","状态"],"MsgStr":null,"MsgTypeId":0,"MyPower":[12,12,13,15],"PageInfo":{"PageIndex":1,"PageSum":0,"ResultSum":9,"ShowNum":20},"ResultNum":9,"Rows":[["60","False","会员1[代理1]","hy1","200.0000","200.0000","A","fgs1<br>0%","gd1<br>20%","zdl1<br>30%","dl1<br>20%","2016-03-19 17:19:13","1"],["61","False","会员2[代理2]","hy2","100.0000","100.0000","A","fgs2<br>20%","gd2<br>10%","zdl2<br>30%","dl2<br>10%","2016-03-19 17:20:14","1"],["62","False","会员3[代理1]","hy3","100.0000","100.0000","A","fgs1<br>0%","gd1<br>20%","zdl1<br>30%","dl1<br>5%","2016-03-19 17:20:57","1"],["63","False","会员4[分公司1]","hy4","500.0000","500.0000","A","fgs1<br>20%","","","","2016-03-19 17:22:55","1"],["68","False","会员5[代理3]","hy5","1000.0000","0.0000","A","fgs3<br>30%","gd3<br>0%","zdl3<br>30%","dl3<br>20%","2016-03-19 22:05:34","1"],["69","False","会员6[分公司3]","hy6","1000.0000","278.0000","A","fgs3<br>40%","","","","2016-03-21 13:59:56","1"],["70","False","会员7[分公司3]","hy7","10000.0000","10000.0000","A","fgs3<br>20%","","","","2016-03-23 13:43:02","1"],["72","False","会员8[分公司4]","hy8","1000000.0000","683171.0000","A","fgs4<br>40%","","","","2016-03-23 13:46:46","1"],["76","False","hy9[代理4]","hy9","1000000.0000","896718.0000","A","fgs4<br>30%","gd4<br>10%","zdl4<br>10%","dl4<br>30%","2016-03-24 16:20:13","1"]],"Succeed":false,"Supers":[],"Variable":null} 

我把你的正则改成/"(w*?)":/g就可以了。你的正则肯定比我好,你可以再看看

一周热门 更多>