|
本帖最后由 1234vba 于 2018-9-6 22:35 编辑
附件下载
Book1.rar
(12.35 KB, 下载次数: 8)
代码如下:
- Sub main()
- Dim js As Object, s$, json$
- s = "[{""ttery"":""b10"",""issue"":""1702084"",""code"":""01,05,02,07,10,09,06,08,04,03"",""code1"":null,""code2"":null,""time"":1536046966000}]"
- Set js = CreateObject("MSScriptControl.ScriptControl")
- js.Language = "JavaScript": js.AddObject "g", Range("a27")
- json = "a=" & s & ";for(i=0;i<a.length;i++){g(i+1,1)=a[i].issue;b=a[i].code.split(',');for(j=0;j<b.length;j++)g(i+1,j+2)=b[j]};"
- js.eval (json)
- End Sub
复制代码 代码效果:
修改如下:(红色部分)
json = "a=" & s & ";for(i=0;i<a.length;i++){g(i+1,1)=a.issue;b=a.code.split();for(j=0;j<b.length;j++)g(i+1,j+2)=b[j]};"
我本想使用Replace 来替换掉 逗号的。(空格替换掉逗号)
但不管怎么修改都不对。
所以尝试 直接处理 定义的变量s
ss = Replace(s, ",", " ") Dim js As Object, s$, json$
s = "[{""ttery"":""b10"",""issue"":""1702084"",""code"":""01,05,02,07,10,09,06,08,04,03"",""code1"":null,""code2"":null,""time"":1536046966000}]"
ss = Replace(s, ",", " ")
Debug.Print ss 结果如下:
[{"ttery":"b10" "issue":"1702084" "code":"01 05 02 07 10 09 06 08 04 03" "code1":null "code2":null "time":1536046966000}] 这里已经显示替换成功,
但接下来的代码 报错了。。
- Private Sub CommandButton1_Click()
- Dim js As Object, s$, json$
- s = "[{""ttery"":""b10"",""issue"":""1702084"",""code"":""01,05,02,07,10,09,06,08,04,03"",""code1"":null,""code2"":null,""time"":1536046966000}]"
- ss = Replace(s, ",", " ")
-
- Debug.Print ss
- Set js = CreateObject("MSScriptControl.ScriptControl")
- js.Language = "JavaScript": js.AddObject "g", Range("a27")
- json = "a=" & ss & ";for(i=0;i<a.length;i++){g(i+1,1)=a[i].issue;b=a[i].code.split();for(j=0;j<b.length;j++)g(i+1,j+2)=b[j]};"
- js.eval (json)
- End Sub
复制代码
报错停在这句
js.eval (json)
来源应该是这句 b=a.code.split();
要如何修改 才能把 逗号 替换成空格 输出呢
请各位老师帮忙
|
|