以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  解析  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=94633)

--  作者:huhu
--  发布时间:2016/12/28 15:11:00
--  解析
假如对方给我返回的是多个{},每个{}里面的格式都是相同的。
下面的是针对单个{}计划表增加一行,多个{},计划表需要增加多行,怎么做呢? 
If dr2 Is Nothing Then
                Dim dl As new ClassLibrary1.Class1()
                Dim Multi As String =dl.getSchInfoByWorkInfo(str1,str2)
                If Multi.Length = 0 Then
                    MessageBox.show("工单号行号:" & str & "没有导入订单系统,请告知计划人员","异常",MessageBoxButtons.OK,MessageBoxIcon.Error)
                Else
                    multi = multi.Replace("{","").Replace("}","")
                    Dim Values() As String
                    Values = Multi.split(",")
                    Dim zd As New Dictionary(Of String, String)
                    zd.Add("u8OrderNo","订单号")
                    zd.Add("u8LineNo","订单行号")
                    zd.Add("productNo","客户物料编码")
                    zd.Add("productType","客户物料名称")
                    zd.Add("bdMaterialNo","博达物料编码")
                    zd.Add("bdMaterialName","博达物料名称")
                    zd.Add("productionQuantity","生产订单数量")
                    zd.Add("typeDscr","类别说明")
                    zd.Add("depName","部门名称")
                    zd.Add("startDate","开工日期")
                    zd.Add("endDate","完工日期")
                    zd.Add("activeOSNo","两化表编号")
                    zd.Add("remark","备注")
                    zd.Add("swVersion","软件版本")
                    Dim rr As Row = Tables("计划表").AddNew
                    For Index As Integer = 0 To Values.Length - 1
                        Dim vrr() As String = Values(Index).split(":")
                        rr(zd(vrr(0))) = vrr(1)
                    Next
                    rr("生产订单号码") = str1
                    rr("工单行号") = str2
                    rr("工单") = str1 & "-" & str2
                    rr.save
                    rr("销售订单_行号") = rr("订单号") & "-" & rr("订单行号")
                    rr.save
                End If
            End If


--  作者:有点色
--  发布时间:2016/12/28 15:25:00
--  

呃,人家给你返回的是json数据吧?参考

 

dim str as string = "{""ty"": ""file"", ""size"": 0}"

msgbox(str)
Dim data As object
Dim JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
Dim ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
    .Language = "Javascript"
    .Timeout = -1
    .AddCode(JscriptCode)
    data = .Run("toObject", str)
End With

msgbox(data.ty)

[此贴子已经被作者于2016/12/28 15:25:40编辑过]

--  作者:huhu
--  发布时间:2016/12/28 16:52:00
--  
[{"u8OrderNo":"SY1510105-1","u8LineNo":"1","productNo":"CBSWI-SWI1563A","productType":"BDCOM S2520PT","bdMaterialNo":"TEROU-ROU0360B","bdMaterialName":"CBOEM-PON0150B","productionQuantity":"2","typeDscr":"正常生产","depName":"制造中心-装配部-批量","startDate":"2015/12/9 0:00:00","endDate":"2015/12/12 0:00:00","activeOSNo":"Oeout7S03e00101","remark":"通用态","swVersion":"09039_2015"},
{"u8OrderNo":"SY1510105-2","u8LineNo":"2","productNo":"CBSWI-SWI1563B","productType":"BDCOM S2520MT","bdMaterialNo":"TEROU-ROU0360A","bdMaterialName":"CBOEM-PON0150A","productionQuantity":"4","typeDscr":"正常生产","depName":"制造中心-装配部-批量","startDate":"2015/12/8 0:00:00","endDate":"2015/12/11 0:00:00","activeOSNo":"Oeout7S03e00102","remark":"通用态","swVersion":"09049_2015"}]
是json格式。
在json.cn能在线解析

图片点击可在新窗口打开查看此主题相关图片如下:json.png
图片点击可在新窗口打开查看

还是不清楚怎么把他们加入到我的计划表里面。如果只有1行数据的,红色代码是通过字典的方式加入的。
请指教。

--  作者:huhu
--  发布时间:2016/12/28 17:33:00
--  
不管一行还是多行,都返回给我的是这种格式。一行一个{},我如何把每行的值写到计划表里面
[{"a":"1","a1":"12"},{"b":"2","b1":"22"},{"c":"3","c1":"333"}]

图片点击可在新窗口打开查看此主题相关图片如下:json2.png
图片点击可在新窗口打开查看


[此贴子已经被作者于2016/12/28 17:38:11编辑过]

--  作者:有点色
--  发布时间:2016/12/28 17:42:00
--  

参考代码

 

Dim str As String = "[{""a"":""1""},{""a"":""2""},{""a"":""3""}]"

msgbox(str)
Dim data As object
Dim JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
Dim ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
    .Language = "Javascript"
    .Timeout = -1
    .AddCode(JscriptCode)
    data = .Run("toObject", str)
End With

 

For Each info As object In data
    output.show(info.a)
Next


--  作者:huhu
--  发布时间:2016/12/29 16:19:00
--  
Dim dr2 As DataRow = DataTables("计划表").SQLFind("工单= \'" & gdhhh.text & "\'")
            If dr2 Is Nothing Then
                Dim dl As new ClassLibrary1.Class1()
                Dim Multi As String =dl.getSchInfoByWorkInfo(str1,str2)
                If Multi.Length = 0 Then
                    MessageBox.show("工单号行号:" & str & "没有导入订单系统,请告知计划人员","异常",MessageBoxButtons.OK,MessageBoxIcon.Error)
                Else              
                    Dim data As object
                    Dim JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
                    Dim ScriptControl = CreateObject("MSScriptControl.ScriptControl")
                    With ScriptControl
                        .Language = "Javascript"
                        .Timeout = -1
                        .AddCode(JscriptCode)
                        data = .Run("toObject", Multi)
                    End With
                    For Each info As object In data
                        Dim rr As Row = Tables("计划表").AddNew
                        rr("订单号") = Info.u8OrderNo
                        rr("订单行号") = Info.u8LineNo
                        rr("客户物料编码") = Info.productNo
                        rr("客户物料名称") = Info.productType
                        rr("博达物料编码") = Info.bdMaterialNo
                        rr("博达物料名称") = Info.bdMaterialName
                        rr("生产订单数量") = Info.productionQuantity
                        rr("类别说明") = Info.typeDscr
                        rr("部门名称") = Info.depName
                        rr("开工日期") = Info.startDate
                        rr("完工日期") = Info.endDate
                        rr("两化表编号") = Info.activeOSNo
                        rr("备注") = Info.remark
                        rr("软件版本") = Info.swVersion
                        rr("销售订单_行号") = rr("订单号") & "-" & rr("订单行号")
                        rr.save                        
                    Next                    
                End If
            End If


老师能发针对红色的代码写一下备注,不理解啥意思。另外for each里面的也应该对的把。

--  作者:有点色
--  发布时间:2016/12/29 16:31:00
--  

运行有什么问题?

 

                    Dim data As object
                    Dim JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}" \'定义一个javascript函数,利用其eval函数转换json数据
                    Dim ScriptControl = CreateObject("MSScriptControl.ScriptControl")
                    With ScriptControl
                        .Language = "Javascript"
                        .Timeout = -1
                        .AddCode(JscriptCode)
                        data = .Run("toObject", Multi) \'运行这个js函数
                    End With

 

其实,你直接用c#的json也是可以的,参考

 

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=89768&skin=0

 

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=76729&skin=0

 

 

 

 

 

--  作者:huhu
--  发布时间:2016/12/30 14:02:00
--  
我在命令窗口运行下面的代码结果就是正确的。
Dim str As String = "[{""workOrderNo"":""SC20160810103"",""workOrderLineNo"":""1"",""u8OrderNo"":""021607102"",""u8LineNo"":""13"",""productNo"":""CBSWI-SWI1630A"",""productType"":""LS6803"",""bdMaterialNo"":""CBSWI-SWI1630A"",""bdMaterialName"":""LS6803"",""productionQuantity"":""1"",""typeDscr"":"""",""depName"":""制造中心-装配部-高端"",""startDate"":""2016-08-17 00:00:00.0"",""endDate"":""2016-08-22 00:00:00.0"",""activeOSNo"":"""",""remark"":"""",""swVersion"":""""},{""workOrderNo"":""SC20160810103"",""workOrderLineNo"":""2"",""u8OrderNo"":""021607102"",""u8LineNo"":""9"",""productNo"":""CBSWI-JCA0772B"",""productType"":""LS68-24GE-SFP-V3"",""bdMaterialNo"":""CBSWI-JCA0772B"",""bdMaterialName"":""LS68-24GE-SFP-V3"",""productionQuantity"":""1"",""typeDscr"":"""",""depName"":""制造中心-装配部-高端"",""startDate"":""2016-08-17 00:00:00.0"",""endDate"":""2016-08-22 00:00:00.0"",""activeOSNo"":"""",""remark"":""1*1"",""swVersion"":""""},{""workOrderNo"":""SC20160810103"",""workOrderLineNo"":""3"",""u8OrderNo"":""021607102"",""u8LineNo"":""10"",""productNo"":""CBSWI-JCA0790B"",""productType"":""LS68-MSU-III-B"",""bdMaterialNo"":""CBSWI-JCA0790B"",""bdMaterialName"":""LS68-MSU-III-B"",""productionQuantity"":""1"",""typeDscr"":"""",""depName"":""制造中心-装配部-高端"",""startDate"":""2016-08-17 00:00:00.0"",""endDate"":""2016-08-22 00:00:00.0"",""activeOSNo"":"""",""remark"":""1*1"",""swVersion"":""""},{""workOrderNo"":""SC20160810103"",""workOrderLineNo"":""4"",""u8OrderNo"":""021607102"",""u8LineNo"":""11"",""productNo"":""CBPOW-POW0112A"",""productType"":""英文中性化LS68-PWR-AC-600"",""bdMaterialNo"":""CBPOW-POW0112A"",""bdMaterialName"":""英文中性化LS68-PWR-AC-600"",""productionQuantity"":""2"",""typeDscr"":"""",""depName"":""制造中心-装配部-高端"",""startDate"":""2016-08-17 00:00:00.0"",""endDate"":""2016-08-22 00:00:00.0"",""activeOSNo"":"""",""remark"":""1*2"",""swVersion"":""""},{""workOrderNo"":""SC20160810103"",""workOrderLineNo"":""5"",""u8OrderNo"":""021607102"",""u8LineNo"":""12"",""productNo"":""CBSWI-JCA0774B"",""productType"":""LS68-12GE-TX/SFP-V3"",""bdMaterialNo"":""CBSWI-JCA0774B"",""bdMaterialName"":""LS68-12GE-TX/SFP-V3"",""productionQuantity"":""1"",""typeDscr"":"""",""depName"":""制造中心-装配部-高端"",""startDate"":""2016-08-17 00:00:00.0"",""endDate"":""2016-08-22 00:00:00.0"",""activeOSNo"":"""",""remark"":""1*1"",""swVersion"":""""}]"
msgbox(str)
Dim data As object
Dim JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
Dim ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
    .Language = "Javascript"
    .Timeout = -1
    .AddCode(JscriptCode)
    data = .Run("toObject", str)
    
End With
For Each info As object In data
    Dim rr As Row = Tables("计划表").AddNew
    rr("生产订单号码") = Info.workOrderNo
    rr("工单行号") = Info.workOrderLineNo
    rr("工单") = rr("生产订单号码") & "-" & rr("工单行号")
    rr("订单号") = Info.u8OrderNo
    rr("订单行号") = Info.u8LineNo
    rr("客户物料编码") = Info.productNo
    rr("客户物料名称") = Info.productType
    rr("博达物料编码") = Info.bdMaterialNo
    rr("博达物料名称") = Info.bdMaterialName
    rr("生产订单数量") = Info.productionQuantity
    rr("类别说明") = Info.typeDscr
    rr("部门名称") = Info.depName
    rr("开工日期") = Info.startDate
    rr("完工日期") = Info.endDate
    rr("两化表编号") = Info.activeOSNo
    rr("备注") = Info.remark
    rr("软件版本") = Info.swVersion
    rr("销售订单_行号") = rr("订单号") & "-" & rr("订单行号")
    rr.save
Next
如果在keydown运行,
就提示错误所在事件:窗口,生产入库,TextBox3,KeyDown
详细错误信息:
缺少 \';
 Dim dl As new ClassLibrary1.Class1()
            Dim Multi As String =dl.getSchInfoByWorkInfo_1(str1,str2)
            If Multi.Length = 0 Then
                MessageBox.show("工单号行号:" & str & "没有导入订单系统,请告知计划人员","异常",MessageBoxButtons.OK,MessageBoxIcon.Error)
            Else                
                msgbox (Multi)
                Dim data As object
                Dim JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
                Dim ScriptControl = CreateObject("MSScriptControl.ScriptControl")
                With ScriptControl
                    .Language = "Javascript"
                    .Timeout = -1
                    .AddCode(JscriptCode)
                    data = .Run("toObject", Multi)                    
                End With
                For Each info As object In data
                    Dim rr As Row = Tables("计划表").AddNew
                    rr("生产订单号码") = Info.workOrderNo
                    rr("工单行号") = Info.workOrderLineNo
                    rr("工单") = rr("生产订单号码") & "-" & rr("工单行号")
                    rr("订单号") = Info.u8OrderNo
                    rr("订单行号") = Info.u8LineNo
                    rr("客户物料编码") = Info.productNo
                    rr("客户物料名称") = Info.productType
                    rr("博达物料编码") = Info.bdMaterialNo
                    rr("博达物料名称") = Info.bdMaterialName
                    rr("生产订单数量") = Info.productionQuantity
                    rr("类别说明") = Info.typeDscr
                    rr("部门名称") = Info.depName
                    rr("开工日期") = Info.startDate
                    rr("完工日期") = Info.endDate
                    rr("两化表编号") = Info.activeOSNo
                    rr("备注") = Info.remark
                    rr("软件版本") = Info.swVersion
                    rr("销售订单_行号") = rr("订单号") & "-" & rr("订单行号")
                    rr.save
                Next
            End If
发现2个msgbox(str)和msgbox(Multi),结果不一样。一个去掉了多余的引号,一个仍然是返回的原值引号仍然保留
msgbox(str)

图片点击可在新窗口打开查看此主题相关图片如下:str.png
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:mutl.png
图片点击可在新窗口打开查看
这是怎么回事呢?怎么改呢?ths
[此贴子已经被作者于2016/12/30 14:03:23编辑过]

--  作者:有点色
--  发布时间:2016/12/30 14:27:00
--  

 编写代码的时候,两个双引号表示一个双引号。你直接取字符串的时候,不需要写两个双引号。


--  作者:huhu
--  发布时间:2016/12/30 15:02:00
--  
接口返回的就是那样的格式。
我该怎么改?